diff mbox

[Fortran,committed] Plug two memory leaks

Message ID 51ED2DE1.3050601@net-b.de
State New
Headers show

Commit Message

Tobias Burnus July 22, 2013, 1:04 p.m. UTC
Found by Coverity. In the first case, "error" gets overridden if status 
is not NULL_TREE. The second case is rather obvious.

Committed as Rev. 201125 after built on x86-64-gnu-linux.

Tobias
diff mbox

Patch

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 201124)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,8 @@ 
+2013-07-21  Tobias Burnus  <burnus@net-b.de>
+
+	* trans-array.c (gfc_array_allocate,
+	gfc_trans_deferred_array): Plug memory leak.
+
 2013-07-21   Ondřej Bílka  <neleai@seznam.cz>
 
 	* trans-decl.c: Fix comment typos.
Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c	(Revision 201124)
+++ gcc/fortran/trans-array.c	(Arbeitskopie)
@@ -5209,7 +5209,7 @@  gfc_array_allocate (gfc_se * se, gfc_expr * expr,
 			      &se->pre, &set_descriptor_block, &overflow,
 			      expr3_elem_size, nelems, expr3, ts);
 
-  if (dimension)
+  if (status == NULL_TREE && dimension)
     {
 
       var_overflow = gfc_create_var (integer_type_node, "overflow");
@@ -5223,8 +5223,7 @@  gfc_array_allocate (gfc_se * se, gfc_expr * expr,
       error = build_call_expr_loc (input_location, gfor_fndecl_runtime_error,
 				   1, msg);
     }
-
-  if (status != NULL_TREE)
+  else if (status != NULL_TREE)
     {
       tree status_type = TREE_TYPE (status);
       stmtblock_t set_status_block;
@@ -8525,10 +8524,12 @@  gfc_trans_deferred_array (gfc_symbol * sym, gfc_wr
       && !sym->attr.save && !sym->attr.result
       && !sym->ns->proc_name->attr.is_main_program)
     {
+      gfc_expr *e;
+      e = has_finalizer ? gfc_lval_expr_from_sym (sym) : NULL;
       tmp = gfc_trans_dealloc_allocated (sym->backend_decl,
-					 sym->attr.codimension,
-					 has_finalizer
-					 ? gfc_lval_expr_from_sym (sym) : NULL);
+					 sym->attr.codimension, e);
+      if (e)
+	gfc_free_expr (e);
       gfc_add_expr_to_block (&cleanup, tmp);
     }