This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[Patch, Fortran, committed] Fix two memory leaks
- From: Tobias Burnus <burnus at net-b dot de>
- To: gcc patches <gcc-patches at gcc dot gnu dot org>, gfortran <fortran at gcc dot gnu dot org>
- Date: Fri, 01 Mar 2013 11:25:16 +0100
- Subject: [Patch, Fortran, committed] Fix two memory leaks
I committed (Rev. 196372) after regtesting on x86-64-gnu-linux the
attached patch.
There are still plenty of leaks in the FE, including surprising ones:
The program "end" leaks memory while some more complicated programs
don't. (Tested with valgrind --leak-check=full and compiling with
-fsyntax-only.)
Tobias
Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog (Revision 196370)
+++ gcc/fortran/ChangeLog (Arbeitskopie)
@@ -1,3 +1,8 @@
+2013-03-01 Tobias Burnus <burnus@net-b.de>
+
+ * trans-decl.c (gfc_trans_deferred_vars): Free expr after use.
+ * trans-io.c (build_dt): Ditto.
+
2013-02-24 Joseph Myers <joseph@codesourcery.com>
* resolve.c (generate_component_assignments): Don't use UTF-8
Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c (Revision 196370)
+++ gcc/fortran/trans-decl.c (Arbeitskopie)
@@ -3818,10 +3818,12 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gf
NULL_TREE, true, NULL,
true);
else
- tmp = gfc_deallocate_scalar_with_status (se.expr, NULL_TREE,
- true,
- gfc_lval_expr_from_sym (sym),
- sym->ts);
+ {
+ gfc_expr *expr = gfc_lval_expr_from_sym (sym);
+ tmp = gfc_deallocate_scalar_with_status (se.expr, NULL_TREE,
+ true, expr, sym->ts);
+ gfc_free_expr (expr);
+ }
}
if (sym->ts.type == BT_CLASS)
{
Index: gcc/fortran/trans-io.c
===================================================================
--- gcc/fortran/trans-io.c (Revision 196370)
+++ gcc/fortran/trans-io.c (Arbeitskopie)
@@ -1782,6 +1782,8 @@ build_dt (tree function, gfc_code * code)
mask |= set_string (&block, &post_block, var, IOPARM_dt_namelist_name,
nmlname);
+ gfc_free_expr (nmlname);
+
if (last_dt == READ)
mask |= IOPARM_dt_namelist_read_mode;