This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Memory leak in intrinsic assignment of allocatable function result
- From: Damian Rouson <damian at rouson dot net>
- To: gfortran <fortran at gcc dot gnu dot org>
- Cc: "Morris, Karla NMN (-EXP)" <knmorri at sandia dot gov>
- Date: Tue, 4 Dec 2012 14:22:29 -0800
- Subject: Memory leak in intrinsic assignment of allocatable function result
Gfortran developers,
I am assisting my staff member Karla Morris (cc'd) in demonstrating a
gfortran memory leak. In my version of her code below, it's possible
I have oversimplified the situation. I'm not sure the leak valgrind
is reporting is associated with the right-hand-side function result in
"a = bar()" or with the left-hand side "a". If valgrind is reporting
a leak associated with "a", then I presume it's not really a leak
because the compiler is not obligated to free deallocate objects
declared in a main program. If valgrind is reporting a leak
associated with a function result, then this test code is sufficient
to demonstrate at least part of the problem we've encountered.
In Karla's actual application, the "bar" procedure is type-bound and
is invoked via a type-bound generic operator that appears in a longer
expression composed of various user-defined operators.
If the results below do in fact demonstrate a leak, I'd love to know
exactly what the one leaky bite holds. Please advise.
Damian
$ gfortran --version
GNU Fortran (MacPorts gcc48 4.8-20121202_0) 4.8.0 20121202 (experimental)
$ cat leak.f90
type foo
end type
type(foo) a
a = bar()
contains
function bar()
type(foo), allocatable :: bar
allocate(bar)
end function
end
$ gfortran leak.f90
$ valgrind ./a.out
==5151== Memcheck, a memory error detector
==5151== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==5151== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==5151== Command: ./a.out
==5151==
--5151-- ./a.out:
--5151-- dSYM directory is missing; consider using --dsymutil=yes
==5151==
==5151== HEAP SUMMARY:
==5151== in use at exit: 1,998 bytes in 33 blocks
==5151== total heap usage: 49 allocs, 16 frees, 5,706 bytes allocated
==5151==
==5151== LEAK SUMMARY:
==5151== definitely lost: 1 bytes in 1 blocks
==5151== indirectly lost: 0 bytes in 0 blocks
==5151== possibly lost: 0 bytes in 0 blocks
==5151== still reachable: 1,997 bytes in 32 blocks
==5151== suppressed: 0 bytes in 0 blocks
==5151== Rerun with --leak-check=full to see details of leaked memory
==5151==
==5151== For counts of detected and suppressed errors, rerun with: -v
==5151== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)