mtrace for a fortran program

Steve Kargl sgk@troutmask.apl.washington.edu
Thu Dec 11 20:46:00 GMT 2008


On Thu, Dec 11, 2008 at 11:40:54AM -0700, Davide Del Vento wrote:
> > The code you posted in
> >
> > http://stackoverflow.com/questions/260192/mtrace-for-a-fortran-program
> >
> > does not leak memory.  If the compiler, in our case gfortran, conforms
> > to the Fortran 95 standard, it will not leak memory.
> 
> thank you very much for your note. It has been incredible useful!
> Actually I am mostly I C/C++ guy, thus I didn't realize the issue.
> In fact the IBM compiler I tested before gfortran was leaking memory,
> thus I thought that was the expected behavior (probably I will fill a
> bug report with them).
> I tried the same source code with both compilers and the
> gfortran-produced executable is not leaking (I made a long lived test
> program and checked with top).
> 
> Of course, changing "allocatable" with "pointer" does leak with gfortran
> too. And the good news is that mtrace is able to detect it! The bad news
> is that it doesn't track the source code line (yes, I compiled with -g)
> but I'll work on that and report onlist if I will find something
> not-obvious.
> 

Yes, pointers can be abused to leak memory or cause segmentation faults.
There is a patch, scheduled for the 4.5 branch, that may help track
down these types of memory leaks.  The patch implements -fruntime-check=memleaks.

There are also plans to redesign and rewrite the internal description
of array descriptors, which may also benefit the "abused pointer leaks
memory" problem.

-- 
Steve



More information about the Fortran mailing list