Retrieving some context from Fortran runtime errors

Steve Kargl sgk@troutmask.apl.washington.edu
Fri Sep 12 18:13:00 GMT 2008


On Fri, Sep 12, 2008 at 07:00:33PM +0200, Dennis Wassel wrote:
> 2008/9/12 Alberto Luaces <aluaces@udc.es>:
> > Hello,
> >
> > I have a C++ program that uses a library written in Fortran. Currently the
> > program stops with this message:
> >
> > Fortran runtime error: Attempt to DEALLOCATE unallocated memory.
> >
> > However, as it doesn't segfaults nor dumps core, I cannot find which
> > DEALLOCATE is the culprit. How could I find it?
> >
> > gfortran gcc version 4.3.1 (Debian 4.3.1-9)
> >
> 
> This solution worked for me; it requires you to have the Fortran
> library available as source, though.
> 
> Compile (at least) the library with -g, then run the executable in gdb
> and set a breakpoint at '_gfortran_runtime_error'. gdb will stop at
> the "Fortran runtime error" somewhere inside libgfortran, but you can
> backtrace your way into your code from there to find the offending
> DEALLOCATE.
> 

I'd suggest adding proper error handling to the Fortran code.

   program test
   real, allocatable :: x(:)
   allocate (x(10))
   x = 1.
   deallocate(x)
   deallocate(x,stat=i)
   if (i /= 0) then
      stop 'Deallocation failed at line 7'
   end if
   end program test

-- 
Steve



More information about the Fortran mailing list