Tools: fix memory leaks

This commit is contained in:
Shahram Najm 2020-01-23 12:55:18 +00:00
parent a39f03398c
commit 8082b4ea78
2 changed files with 15 additions and 0 deletions

View File

@ -637,6 +637,7 @@ void grib_fieldset_delete(grib_fieldset* set)
grib_fieldset_delete_fields(set);
grib_fieldset_delete_int_array(set->order);
grib_fieldset_delete_int_array(set->filter);
grib_fieldset_delete_order_by(c, set->order_by);
grib_context_free(c, set);
}

View File

@ -146,6 +146,7 @@ static grib_handle* grib_handle_new_from_file_x(grib_context* c, FILE* f, int mo
int grib_tool(int argc, char** argv)
{
int ret = 0;
int i = 0;
grib_context* c = grib_context_get_default();
global_options.context = c;
@ -193,6 +194,13 @@ int grib_tool(int argc, char** argv)
if (global_options.dump_filename)
fclose(dump_file);
/* Free memory */
for (i = 0; i < global_options.print_keys_count; i++) {
if (global_options.print_keys[i].name) {
free((char*)global_options.print_keys[i].name);
}
}
return ret;
}
@ -286,6 +294,9 @@ static int grib_tool_with_orderby(grib_runtime_options* options)
grib_tool_finalise_action(options);
grib_fieldset_delete(set);
free(filenames);
return 0;
}
@ -722,6 +733,9 @@ static void grib_tools_set_print_keys(grib_runtime_options* options, grib_handle
options->print_keys_count);
exit(1);
}
if (options->print_keys[options->print_keys_count].name) {
free((char*)options->print_keys[options->print_keys_count].name);
}
options->print_keys[options->print_keys_count].name = strdup(name);
if (strlen(name) > options->default_print_width)
options->default_print_width = (int)strlen(name);