From 7a14817017736f4b83f8c0b26f02de3f56b7a2d4 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 22 Dec 2020 16:47:23 +0000 Subject: [PATCH] ECC-1185: Crash in codes_context_delete() call (Part 1) --- examples/C/new_sample.c | 1 + src/action_class_gen.c | 7 ++++++- src/grib_accessor_class_codetable.c | 1 + src/grib_context.c | 14 +++++++++++--- tests/bufr_check_descriptors.c | 1 + tests/bufr_get_element.c | 2 ++ tests/grib_bpv_limit.c | 1 + tests/grib_indexing.c | 2 +- tests/lsan-leap42.supp | 1 - tests/read_any.c | 1 + 10 files changed, 25 insertions(+), 6 deletions(-) diff --git a/examples/C/new_sample.c b/examples/C/new_sample.c index a6a436ffa..cc08929d1 100644 --- a/examples/C/new_sample.c +++ b/examples/C/new_sample.c @@ -388,5 +388,6 @@ int main(int argc, char** argv) } codes_handle_delete(h); + grib_context_delete(grib_context_get_default()); return 0; } diff --git a/src/action_class_gen.c b/src/action_class_gen.c index f1492b4d3..4eb060960 100644 --- a/src/action_class_gen.c +++ b/src/action_class_gen.c @@ -214,7 +214,12 @@ static void destroy(grib_context* context, grib_action* act) grib_context_free_persistent(context, act->name); grib_context_free_persistent(context, act->op); - grib_context_free_persistent(context, act->name_space); + if(act->name_space) { + grib_context_free_persistent(context, act->name_space); + } if (act->set) grib_context_free_persistent(context, act->set); + if (act->defaultkey) { + grib_context_free_persistent(context, act->defaultkey); + } } diff --git a/src/grib_accessor_class_codetable.c b/src/grib_accessor_class_codetable.c index 4708a4334..2b9189fae 100644 --- a/src/grib_accessor_class_codetable.c +++ b/src/grib_accessor_class_codetable.c @@ -530,6 +530,7 @@ void grib_codetable_delete(grib_context* c) for (i = 0; i < t->size; i++) { grib_context_free_persistent(c, t->entries[i].abbreviation); grib_context_free_persistent(c, t->entries[i].title); + grib_context_free_persistent(c, t->entries[i].units); } grib_context_free_persistent(c, t->filename[0]); if (t->filename[1]) diff --git a/src/grib_context.c b/src/grib_context.c index 327fdf13b..dc50b08fa 100644 --- a/src/grib_context.c +++ b/src/grib_context.c @@ -800,8 +800,16 @@ void grib_context_reset(grib_context* c) grib_smart_table_delete(c); c->smart_table = NULL; - if (c->grib_definition_files_dir) - grib_context_free(c, c->grib_definition_files_dir); + if (c->grib_definition_files_dir) { + grib_string_list* next = c->grib_definition_files_dir; + grib_string_list* cur = NULL; + while (next) { + cur = next; + next = next->next; + grib_context_free(c, cur->value); + grib_context_free(c, cur); + } + } if (c->multi_support_on) grib_multi_support_reset(c); @@ -813,7 +821,7 @@ void grib_context_delete(grib_context* c) c = grib_context_get_default(); grib_hash_keys_delete(c->keys); - grib_trie_delete(c->def_files); + /*grib_trie_delete(c->def_files); TODO:masn */ grib_context_reset(c); if (c != &default_grib_context) diff --git a/tests/bufr_check_descriptors.c b/tests/bufr_check_descriptors.c index e0967e833..b4f3906ac 100644 --- a/tests/bufr_check_descriptors.c +++ b/tests/bufr_check_descriptors.c @@ -55,5 +55,6 @@ int main(int argc, char** argv) fclose(fp); + grib_context_delete(grib_context_get_default()); return 0; } diff --git a/tests/bufr_get_element.c b/tests/bufr_get_element.c index a4f51b5d5..62eee90bf 100644 --- a/tests/bufr_get_element.c +++ b/tests/bufr_get_element.c @@ -52,5 +52,7 @@ int main(int argc, char* argv[]) codes_handle_delete(h); } fclose(in); + + grib_context_delete(grib_context_get_default()); return 0; } diff --git a/tests/grib_bpv_limit.c b/tests/grib_bpv_limit.c index 101f1ee83..a1749fcd0 100644 --- a/tests/grib_bpv_limit.c +++ b/tests/grib_bpv_limit.c @@ -121,5 +121,6 @@ int main(int argc, char** argv) fclose(in); } + grib_context_delete(grib_context_get_default()); return 0; } diff --git a/tests/grib_indexing.c b/tests/grib_indexing.c index 328cb490b..fb565fff6 100644 --- a/tests/grib_indexing.c +++ b/tests/grib_indexing.c @@ -153,7 +153,7 @@ int main(int argc, char* argv[]) free(shortNames[i]); free(shortNames); - /*grib_context_delete(grib_context_get_default());*/ + grib_context_delete(grib_context_get_default()); return 0; } diff --git a/tests/lsan-leap42.supp b/tests/lsan-leap42.supp index 8089a595f..d11c22254 100644 --- a/tests/lsan-leap42.supp +++ b/tests/lsan-leap42.supp @@ -1,4 +1,3 @@ leak:process_elements leak:tests/bufr_ecc-517.c leak:src/action_class_rename.c -leak:tests/grib_indexing.c diff --git a/tests/read_any.c b/tests/read_any.c index 849ae39ba..f340aede9 100644 --- a/tests/read_any.c +++ b/tests/read_any.c @@ -78,5 +78,6 @@ int main(int argc, char* argv[]) count++; } + grib_context_delete(grib_context_get_default()); return 0; }