Further memory leaks fixed

This commit is contained in:
Shahram Najm 2020-07-10 23:37:00 +01:00
parent c1e414116d
commit 230797d018
7 changed files with 13 additions and 3 deletions

View File

@ -313,6 +313,7 @@ static int select_area(grib_accessor* a)
if (nsubsets != 0) { if (nsubsets != 0) {
subsets_ar = grib_iarray_get_array(subsets); subsets_ar = grib_iarray_get_array(subsets);
ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets);
grib_context_free(c, subsets_ar);
if (ret) if (ret)
return ret; return ret;

View File

@ -443,6 +443,7 @@ static int select_datetime(grib_accessor* a)
if (nsubsets != 0) { if (nsubsets != 0) {
subsets_ar = grib_iarray_get_array(subsets); subsets_ar = grib_iarray_get_array(subsets);
ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets);
grib_context_free(c, subsets_ar);
if (ret) if (ret)
return ret; return ret;

View File

@ -207,6 +207,7 @@ static int apply_thinning(grib_accessor* a)
if (nsubsets != 0) { if (nsubsets != 0) {
subsets_ar = grib_iarray_get_array(subsets); subsets_ar = grib_iarray_get_array(subsets);
ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets);
grib_context_free(c, subsets_ar);
if (ret) if (ret)
return ret; return ret;
@ -218,6 +219,7 @@ static int apply_thinning(grib_accessor* a)
if (ret) if (ret)
return ret; return ret;
} }
grib_iarray_delete(subsets);
} }
else { else {
return GRIB_NOT_IMPLEMENTED; return GRIB_NOT_IMPLEMENTED;

View File

@ -116,14 +116,17 @@ grib_expression* new_sub_string_expression(grib_context* c, const char* value, s
if (length == 0) { if (length == 0) {
grib_context_log(c, GRIB_LOG_ERROR, "Invalid substring: length must be > 0"); grib_context_log(c, GRIB_LOG_ERROR, "Invalid substring: length must be > 0");
grib_context_free_persistent(c, e);
return NULL; return NULL;
} }
if (start > slen) { /* to catch a -ve number passed to start */ if (start > slen) { /* to catch a -ve number passed to start */
grib_context_log(c, GRIB_LOG_ERROR, "Invalid substring: start=%lu", start); grib_context_log(c, GRIB_LOG_ERROR, "Invalid substring: start=%lu", start);
grib_context_free_persistent(c, e);
return NULL; return NULL;
} }
if (start + length > slen) { if (start + length > slen) {
grib_context_log(c, GRIB_LOG_ERROR, "Invalid substring: start(=%lu)+length(=%lu) > length('%s'))", start, length, value); grib_context_log(c, GRIB_LOG_ERROR, "Invalid substring: start(=%lu)+length(=%lu) > length('%s'))", start, length, value);
grib_context_free_persistent(c, e);
return NULL; return NULL;
} }

View File

@ -1440,9 +1440,11 @@ grib_action* grib_action_from_filter(const char* filter)
grib_action* a = NULL; grib_action* a = NULL;
grib_context* context = grib_context_get_default(); grib_context* context = grib_context_get_default();
a = grib_parse_file(context, filter); a = grib_parse_file(context, filter);
grib_context_free_persistent(context, context->grib_reader->first->filename); grib_context_free_persistent(context, context->grib_reader->first->filename);
grib_context_free_persistent(context, context->grib_reader->first); grib_context_free_persistent(context, context->grib_reader->first);
grib_context_free_persistent(context, context->grib_reader); grib_context_free_persistent(context, context->grib_reader);
context->grib_reader = NULL; context->grib_reader = NULL;
return a; return a;
} }

View File

@ -351,6 +351,7 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha
*newline = 1; *newline = 1;
cols = 0; cols = 0;
} }
grib_context_free(h->context, cvals[i]);
} }
} }
grib_context_free(h->context, cvals); grib_context_free(h->context, cvals);
@ -485,6 +486,7 @@ int grib_recompose_print(grib_handle* h, grib_accessor* observer, const char* un
case ']': case ']':
loc[mode] = 0; loc[mode] = 0;
mode = -1; mode = -1;
if(al) grib_accessors_list_delete(h->context, al);
al = grib_find_accessors_list(h, loc); /* This allocates memory */ al = grib_find_accessors_list(h, loc); /* This allocates memory */
if (!al) { if (!al) {
if (!fail) { if (!fail) {

View File

@ -1,7 +1,6 @@
leak:tools/grib_filter.c leak:process_elements
leak:tools/bufr_filter.c
leak:tools/bufr_dump.c
leak:tools/bufr_compare.c leak:tools/bufr_compare.c
leak:tools/gts_filter.c leak:tools/gts_filter.c
leak:src/action_class_rename.c leak:src/action_class_rename.c
leak:tools/grib_to_netcdf.c leak:tools/grib_to_netcdf.c
leak:tests/bufr_ecc-517.c