This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [Patch, fortran] Runtime memory leak checking.
- From: Jack Howarth <howarth at bromo dot med dot uc dot edu>
- To: Paul Richard Thomas <paul dot richard dot thomas at gmail dot com>
- Cc: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 29 Nov 2008 12:59:13 -0500
- Subject: Re: [Patch, fortran] Runtime memory leak checking.
- References: <339c37f20811290935le65cc42q871adff5cde4874a@mail.gmail.com>
On Sat, Nov 29, 2008 at 06:35:58PM +0100, Paul Richard Thomas wrote:
> This patch is almost entirely due to FX Coudert; I added the updating
> of gfc_current_locus in trans.c, the testcase and the ChangeLogs. I
> also corrected one error.
>
> The patch implements checking for memory leaks, such that:
>
> [prt@localhost mem-check]# cat m*.f90
> ! { dg-do run }
> ! { dg-options = "-fruntime-check=memleaks" }
> !
> ! Test the runtime check for memory leaks.
> !
> integer(4), pointer :: i(:)
> allocate (i(10))
> end
> ! { dg-output "found 1 memory leaks" }
>
> [prt@localhost mem-check]# /irun/bin/gfortran -static
> -fruntime-check=memleaks m*.f90;./a.out
>
>
> Fortran runtime checking: found 1 memory leaks
> - at line 7 of file 'mem_check_1.f90', allocation of 40.0 B (address
> 0x1749ee0)
>
> Peak user-allocated memory: 40.0 B
> Peak memory created by the compiler for temporaries: 0.00 B
>
> When applied to some of the allocatable component testcases, such as:
> [prt@localhost mem-check]# /irun/bin/gfortran -static
> -fruntime-check=memleaks
> /svn/trunk/gcc/testsuite/gfortran.dg/alloc_comp_basics_5.f90;./a.out
>
>
> Fortran runtime checking: found 1 memory leaks
> - at line 25 of file
> '/svn/trunk/gcc/testsuite/gfortran.dg/alloc_comp_basics_5.f90',
> allocation of 40.0 B (address 0x24fdee0)
>
> Peak user-allocated memory: 40.0 B
> Peak memory created by the compiler for temporaries: 0.00 B
>
> It also adds hooks for memusage and recursion in runtime.
>
> All the action happens in libgfortran/runtime/mem-check.c. This sets
> up and populates a hash table with allocations of temporaries.
> Deallocation removes the entries and anything that is left at the end
> of execution represents a memory leak. The modifications to trans*.c
> implement the calls when memory is alloctaed or freed, if the
> runtime-check flag is set.
>
> Bootstrapped and regtested on FC9/x86_i64.
>
> OK to go on ice ready for 4.5? (Is there any appetite to add it to 4.4?)
>
> Paul
>
Paul,
Wouldn't this feature be a useful tool in debugging some of the
existing PRs for gcc 4.4?
Jack