[Patch, Fortran, F03] PR 80983: memory leak when calling procedure-pointer component with allocatable result
Janus Weil
janus@gcc.gnu.org
Thu Jun 15 12:07:00 GMT 2017
Hi all,
the attached patch fixes a runtime memory leak with procedure-pointer
components (PPCs). gfortran correctly deallocates scalar allocatable
function results (also for procedure pointers), but fails to do so for
PPCs, which is cured by my patch.
[Note: Since gfortran translates any type-bound procedure call into a
PPC call internally, the patch also cures memory leaks with TBPs.]
It regtests cleanly on x86_64-linux-gnu. Ok for trunk?
Cheers,
Janus
2017-06-15 Janus Weil <janus@gcc.gnu.org>
PR fortran/70983
* trans-expr.c (gfc_conv_procedure_call): Deallocate the result of
scalar allocatable procedure-pointer components.
2017-06-15 Janus Weil <janus@gcc.gnu.org>
PR fortran/70983
* gfortran.dg/proc_ptr_comp_51.f90: New test.
-------------- next part --------------
Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c (revision 249130)
+++ gcc/fortran/trans-expr.c (working copy)
@@ -6132,7 +6132,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol *
after use. This necessitates the creation of a temporary to
hold the result to prevent duplicate calls. */
if (!byref && sym->ts.type != BT_CHARACTER
- && sym->attr.allocatable && !sym->attr.dimension && !comp)
+ && ((sym->attr.allocatable && !sym->attr.dimension && !comp)
+ || (comp && comp->attr.allocatable && !comp->attr.dimension)))
{
tmp = gfc_create_var (TREE_TYPE (se->expr), NULL);
gfc_add_modify (&se->pre, tmp, se->expr);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: proc_ptr_comp_51.f90
Type: text/x-fortran
Size: 824 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20170615/092be407/attachment.bin>
More information about the Gcc-patches
mailing list