[Patch, Fortran] PR 80121: Memory leak with derived-type intent(out) argument

Janus Weil janus@gcc.gnu.org
Sat Apr 22 21:58:00 GMT 2017


Hi all,

the patch in the attachment fixes a memory leak by auto-deallocating
the allocatable components of an allocatable intent(out) argument.

Regtests cleanly on x86_64-linux-gnu. Ok for trunk?

Cheers,
Janus


2017-04-22  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/80121
    * trans-types.c (gfc_conv_procedure_call): Deallocate the components
    of allocatable intent(out) arguments.

2017-04-22  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/80121
    * gfortran.dg/intent_out_9.f90: New test case.
-------------- next part --------------
Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c	(revision 247077)
+++ gcc/fortran/trans-expr.c	(working copy)
@@ -5454,6 +5454,16 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol *
 	      if (fsym && fsym->attr.allocatable
 		  && fsym->attr.intent == INTENT_OUT)
 		{
+		  if (fsym->ts.type == BT_DERIVED
+		      && fsym->ts.u.derived->attr.alloc_comp)
+		  {
+		    // deallocate the components first
+		    tmp = gfc_deallocate_alloc_comp (fsym->ts.u.derived,
+						     parmse.expr, e->rank);
+		    if (tmp != NULL_TREE)
+		      gfc_add_expr_to_block (&se->pre, tmp);
+		  }
+
 		  tmp = build_fold_indirect_ref_loc (input_location,
 						     parmse.expr);
 		  if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: intent_out_9.f90
Type: text/x-fortran
Size: 678 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20170422/b5ce48ca/attachment.bin>


More information about the Fortran mailing list