This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

Re: [Patch, fortran] Runtime memory leak checking.


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


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