diff mbox

[Fortran,committed] Plug two memory leaks

Message ID 51ED34CF.2090206@net-b.de
State New
Headers show

Commit Message

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

I managed to commit an early draft of the patch - I meant to apply the 
one attached (relative diff) instead.

Committed follow-up fix as Rev. 201129  after building and regtesting on 
x86-64-gnu-linux.

Tobias
diff mbox

Patch

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 201125)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,5 +1,9 @@ 
 2013-07-22  Tobias Burnus  <burnus@net-b.de>
 
+	* trans-array.c (gfc_array_allocate): Correct memory-leak patch.
+
+2013-07-22  Tobias Burnus  <burnus@net-b.de>
+
 	* trans-array.c (gfc_array_allocate,
 	gfc_trans_deferred_array): Plug memory leak.
 
Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c	(Revision 201125)
+++ gcc/fortran/trans-array.c	(Arbeitskopie)
@@ -5209,29 +5209,31 @@  gfc_array_allocate (gfc_se * se, gfc_expr * expr,
 			      &se->pre, &set_descriptor_block, &overflow,
 			      expr3_elem_size, nelems, expr3, ts);
 
-  if (status == NULL_TREE && dimension)
+  if (dimension)
     {
-
       var_overflow = gfc_create_var (integer_type_node, "overflow");
       gfc_add_modify (&se->pre, var_overflow, overflow);
 
-      /* Generate the block of code handling overflow.  */
-      msg = gfc_build_addr_expr (pchar_type_node,
-		gfc_build_localized_cstring_const
+      if (status == NULL_TREE)
+	{
+	  /* Generate the block of code handling overflow.  */
+	  msg = gfc_build_addr_expr (pchar_type_node,
+		    gfc_build_localized_cstring_const
   			("Integer overflow when calculating the amount of "
   			 "memory to allocate"));
-      error = build_call_expr_loc (input_location, gfor_fndecl_runtime_error,
-				   1, msg);
-    }
-  else if (status != NULL_TREE)
-    {
-      tree status_type = TREE_TYPE (status);
-      stmtblock_t set_status_block;
+	  error = build_call_expr_loc (input_location,
+				       gfor_fndecl_runtime_error, 1, msg);
+	}
+      else
+	{
+	  tree status_type = TREE_TYPE (status);
+	  stmtblock_t set_status_block;
 
-      gfc_start_block (&set_status_block);
-      gfc_add_modify (&set_status_block, status,
-		      build_int_cst (status_type, LIBERROR_ALLOCATION));
-      error = gfc_finish_block (&set_status_block);
+	  gfc_start_block (&set_status_block);
+	  gfc_add_modify (&set_status_block, status,
+			  build_int_cst (status_type, LIBERROR_ALLOCATION));
+	  error = gfc_finish_block (&set_status_block);
+	}
     }
 
   gfc_start_block (&elseblock);