Patchwork [Fortran,committed] Fix two memory leaks

login
register
mail settings
Submitter Tobias Burnus
Date March 1, 2013, 10:25 a.m.
Message ID <5130820C.3070104@net-b.de>
Download mbox | patch
Permalink /patch/224281/
State New
Headers show

Comments

Tobias Burnus - March 1, 2013, 10:25 a.m.
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

Patch

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;