From 15d1b2cd2550458da8565b9b1a60d98290acaa28 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 15 Jan 2014 16:51:44 +0000 Subject: [PATCH] Fix errors/warnings reported by cppcheck --- src/action_class_remove.c | 6 ++++-- src/action_class_write.c | 1 + src/grib_db.c | 7 ++++--- src/grib_fieldset.c | 7 ++++--- src/grib_handle.c | 25 +++++++++++-------------- src/grib_index.c | 3 ++- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/action_class_remove.c b/src/action_class_remove.c index 40ab06753..7bb00085e 100644 --- a/src/action_class_remove.c +++ b/src/action_class_remove.c @@ -101,11 +101,13 @@ static void compile(grib_action* act, grib_compiler* compiler) fprintf(compiler->out,");\n"); } -static void remove_accessor(grib_accessor *a){ - grib_section* s = a->parent; +static void remove_accessor(grib_accessor *a) +{ + grib_section* s = NULL; int id; if (!a || !a->previous) return; + s = a->parent; if (a->parent->h->use_trie && *(a->all_names[0]) != '_') { id=grib_hash_keys_get_id(a->parent->h->context->keys,a->all_names[0]); diff --git a/src/action_class_write.c b/src/action_class_write.c index fe5b73fd6..54a9c624f 100755 --- a/src/action_class_write.c +++ b/src/action_class_write.c @@ -161,6 +161,7 @@ static int execute(grib_action* act, grib_handle *h) ioerr = errno; grib_context_log(act->context, (GRIB_LOG_ERROR) | (GRIB_LOG_PERROR), "Error writing to %s", filename); + free(zeros); return GRIB_IO_PROBLEM; } free(zeros); diff --git a/src/grib_db.c b/src/grib_db.c index 13aa9b975..8afb7947e 100644 --- a/src/grib_db.c +++ b/src/grib_db.c @@ -748,11 +748,12 @@ static int grib_db_resize_int_array(grib_int_array* a,size_t newsize) { return err; } -static void grib_db_delete_int_array(grib_int_array* f) { - - grib_context* c=f->context; +static void grib_db_delete_int_array(grib_int_array* f) +{ + grib_context* c = NULL; if (!f) return; + c = f->context; grib_context_free(c,f->el); grib_context_free(c,f); diff --git a/src/grib_fieldset.c b/src/grib_fieldset.c index f7c403f74..2962d966e 100644 --- a/src/grib_fieldset.c +++ b/src/grib_fieldset.c @@ -736,11 +736,12 @@ static int grib_fieldset_resize_int_array(grib_int_array* a,size_t newsize) { return err; } -static void grib_fieldset_delete_int_array(grib_int_array* f) { - - grib_context* c=f->context; +static void grib_fieldset_delete_int_array(grib_int_array* f) +{ + grib_context* c = NULL; if (!f) return; + c = f->context; grib_context_free(c,f->el); grib_context_free(c,f); diff --git a/src/grib_handle.c b/src/grib_handle.c index 0a626b749..5f54ae207 100644 --- a/src/grib_handle.c +++ b/src/grib_handle.c @@ -272,8 +272,8 @@ grib_handle* grib_handle_new_from_samples ( grib_context* c, const char* name ) return g; } - -int grib_write_message(grib_handle* h,const char* file,const char* mode) { +int grib_write_message(grib_handle* h,const char* file,const char* mode) +{ FILE* fh=0; int err; const void *buffer; size_t size; @@ -284,10 +284,14 @@ int grib_write_message(grib_handle* h,const char* file,const char* mode) { return GRIB_IO_PROBLEM; } err=grib_get_message(h,&buffer,&size); - if (err) return err; + if (err) { + fclose(fh); + return err; + } if(fwrite(buffer,1,size,fh) != size) { perror(file); + fclose(fh); return GRIB_IO_PROBLEM; } if (fclose(fh) != 0) { @@ -355,8 +359,6 @@ grib_handle* grib_handle_new_from_partial_message ( grib_context* c,void* data, return grib_handle_create ( gl, c, data, buflen ); } - - grib_handle* grib_handle_new_from_message ( grib_context* c,void* data, size_t buflen ) { grib_handle *gl = NULL; @@ -516,7 +518,7 @@ static grib_handle* grib_handle_new_multi ( grib_context* c,unsigned char** data if ( !gl ) { *error = GRIB_DECODING_ERROR; - grib_context_log ( gl->context, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); + grib_context_log ( c, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); return NULL; } @@ -673,7 +675,7 @@ static grib_handle* grib_handle_new_from_file_multi ( grib_context* c, FILE* f,i if ( !gl ) { *error = GRIB_DECODING_ERROR; - grib_context_log ( gl->context, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); + grib_context_log ( c, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); grib_context_free ( c,data ); return NULL; } @@ -745,7 +747,7 @@ grib_handle* eccode_gts_new_from_file ( grib_context* c, FILE* f,int headers_onl if ( !gl ) { *error = GRIB_DECODING_ERROR; - grib_context_log ( gl->context, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); + grib_context_log ( c, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); grib_context_free ( c,data ); return NULL; } @@ -786,7 +788,7 @@ grib_handle* eccode_bufr_new_from_file ( grib_context* c, FILE* f,int headers_on if ( !gl ) { *error = GRIB_DECODING_ERROR; - grib_context_log ( gl->context, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); + grib_context_log ( c, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); grib_context_free ( c,data ); return NULL; } @@ -1232,7 +1234,6 @@ static void grib2_build_message ( grib_context* context,unsigned char* sections[ grib_encode_unsigned_long ( *data,msglen,&bitp,64 ); *len=msglen; - } void grib_multi_support_on ( grib_context* c ) @@ -1324,7 +1325,6 @@ static grib_multi_support* grib_get_multi_support ( grib_context* c, FILE* f ) return gm; } - void grib_multi_support_reset ( grib_context* c ) { grib_multi_support* gm=c->multi_support; @@ -1342,7 +1342,6 @@ void grib_multi_support_reset ( grib_context* c ) grib_context_free ( c,gm ); gm=NULL; } - } static grib_multi_support* grib_multi_support_new ( grib_context* c ) @@ -1363,5 +1362,3 @@ static grib_multi_support* grib_multi_support_new ( grib_context* c ) return gm; } - - diff --git a/src/grib_index.c b/src/grib_index.c index 53db06d3a..ad7a26a25 100644 --- a/src/grib_index.c +++ b/src/grib_index.c @@ -1259,10 +1259,11 @@ grib_handle* grib_index_get_handle(grib_field* field,int *err) static int grib_index_execute(grib_index* index) { - grib_index_key* keys=index->keys; + grib_index_key* keys = NULL; grib_field_tree* fields; if (!index) return GRIB_INTERNAL_ERROR; + keys = index->keys; fields=index->fields; index->rewind=0;