diff options
author | Bernhard Reutner-Fischer <aldot@gcc.gnu.org> | 2018-10-21 15:55:40 +0200 |
---|---|---|
committer | Bernhard Reutner-Fischer <aldot@gcc.gnu.org> | 2021-10-30 18:45:11 +0200 |
commit | 75c9fa318e31b5ead027eb5e8523d9879bc286ff (patch) | |
tree | dde25869f605bd4d0484554367566eaece7428f9 /gcc/fortran/parse.c | |
parent | db3f6783bde503ab1e361dda47343f0644df7515 (diff) | |
download | gcc-75c9fa318e31b5ead027eb5e8523d9879bc286ff.zip gcc-75c9fa318e31b5ead027eb5e8523d9879bc286ff.tar.gz gcc-75c9fa318e31b5ead027eb5e8523d9879bc286ff.tar.bz2 |
Fix memory leak of gsymbol
We did not free global symbols. For a simplified abstract_type_3.f90
valgrind reports:
96 bytes in 1 blocks are still reachable in loss record 461 of 602
at 0x48377D5: calloc (vg_replace_malloc.c:711)
by 0x21257C3: xcalloc (xmalloc.c:162)
by 0x98611B: gfc_get_gsymbol(char const*) (symbol.c:4341)
by 0x932C58: parse_module() (parse.c:5912)
by 0x9336F8: gfc_parse_file() (parse.c:6236)
by 0x991449: gfc_be_parse_file() (f95-lang.c:204)
by 0x11D8EDE: compile_file() (toplev.c:455)
by 0x11DB9C3: do_compile() (toplev.c:2170)
by 0x11DBCAF: toplev::main(int, char**) (toplev.c:2305)
by 0x2045D37: main (main.c:39)
This patch reduces this to
LEAK SUMMARY:
definitely lost: 344 bytes in 1 blocks
indirectly lost: 3,024 bytes in 4 blocks
possibly lost: 0 bytes in 0 blocks
- still reachable: 1,576,174 bytes in 2,277 blocks
+ still reachable: 1,576,078 bytes in 2,276 blocks
suppressed: 0 bytes in 0 blocks
gcc/fortran/ChangeLog:
2018-10-21 Bernhard Reutner-Fischer <aldot@gcc.gnu.org>
* parse.c (clean_up_modules): Free gsym.
Diffstat (limited to 'gcc/fortran/parse.c')
-rw-r--r-- | gcc/fortran/parse.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c index b1e73ee..12aa80e 100644 --- a/gcc/fortran/parse.c +++ b/gcc/fortran/parse.c @@ -6569,7 +6569,7 @@ resolve_all_program_units (gfc_namespace *gfc_global_ns_list) static void -clean_up_modules (gfc_gsymbol *gsym) +clean_up_modules (gfc_gsymbol *&gsym) { if (gsym == NULL) return; @@ -6577,14 +6577,18 @@ clean_up_modules (gfc_gsymbol *gsym) clean_up_modules (gsym->left); clean_up_modules (gsym->right); - if (gsym->type != GSYM_MODULE || !gsym->ns) + if (gsym->type != GSYM_MODULE) return; - gfc_current_ns = gsym->ns; - gfc_derived_types = gfc_current_ns->derived_types; - gfc_done_2 (); - gsym->ns = NULL; - return; + if (gsym->ns) + { + gfc_current_ns = gsym->ns; + gfc_derived_types = gfc_current_ns->derived_types; + gfc_done_2 (); + gsym->ns = NULL; + } + free (gsym); + gsym = NULL; } |