This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran, F03] PR 80983: memory leak when calling procedure-pointer component with allocatable result


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.

Attachment: pr80983.diff
Description: Text document

! { dg-do compile }
!
! PR 80983: [F03] memory leak when calling procedure-pointer component with allocatable result
!
! Contributed by Janus Weil <janus@gcc.gnu.org>

program test
  implicit none

  type :: concrete_type
    procedure (alloc_integer), pointer, nopass :: alloc
  end type

  procedure (alloc_integer), pointer :: pp

  type(concrete_type) :: concrete

  print *, alloc_integer()     ! case #1: plain function

  pp => alloc_integer
  print *, pp()                ! case #2: procedure pointer

  concrete % alloc => alloc_integer
  print *, concrete % alloc()  ! case #3: procedure-pointer component

contains

   function alloc_integer() result(res)
      integer, allocatable :: res
      allocate(res, source=13)
   end function

end

! { dg-final { scan-tree-dump-times "__builtin_free" 3 "original" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]