|
From: Steven J. P. <sj...@sa...> - 2004-03-05 16:54:31
|
I couldn't find anything specific in the docs about Fortran, other
than a statement that valgrind works with executables from all
languages, including Fortran.
But a simple program like this generates no errors or memory leaks
when run under valgrind-2.0.0, whereas the equivalent C code flags
both. The 1st 2 lines are f90; replacing them with the 3rd line is
f77.
integer, allocatable :: a(:)
allocate(a(100))
c integer a(100)
i = 101
a(i) = 1
write (6,*) a(i)
end
Is valgrind not able to catch that kind of error/leak in Fortran?
Seems odd, since allocate is presumably a wrapper on malloc.
Steve
|
|
From: Nicholas N. <nj...@ca...> - 2004-03-05 17:11:24
|
On Fri, 5 Mar 2004, Steven J. Plimpton wrote: > I couldn't find anything specific in the docs about Fortran, other > than a statement that valgrind works with executables from all > languages, including Fortran. > > But a simple program like this generates no errors or memory leaks > when run under valgrind-2.0.0, whereas the equivalent C code flags > both. The 1st 2 lines are f90; replacing them with the 3rd line is > f77. > > integer, allocatable :: a(:) > allocate(a(100)) > c integer a(100) > > i = 101 > a(i) = 1 > write (6,*) a(i) > end > > Is valgrind not able to catch that kind of error/leak in Fortran? > Seems odd, since allocate is presumably a wrapper on malloc. Valgrind works at the assembly level, except it intercepts a few functions like malloc(). I would guess that 'allocate' isn't a wrapper on malloc, and so Valgrind can't know as much about what's happening and thus isn't flagging the error -- try --trace-malloc=yes to see if it is or not. N |
|
From: Tom H. <th...@cy...> - 2004-03-05 17:19:35
|
In message <E1A...@sa...>
Steven J. Plimpton <sj...@sa...> wrote:
> But a simple program like this generates no errors or memory leaks
> when run under valgrind-2.0.0, whereas the equivalent C code flags
> both. The 1st 2 lines are f90; replacing them with the 3rd line is
> f77.
>
> integer, allocatable :: a(:)
> allocate(a(100))
> c integer a(100)
>
> i = 101
> a(i) = 1
> write (6,*) a(i)
> end
>
> Is valgrind not able to catch that kind of error/leak in Fortran?
It should be able to. It won't catch the F77 case though, as that
is an array which is on the stack not the heap. It wouldn't catch
that in C code either.
> Seems odd, since allocate is presumably a wrapper on malloc.
Is it? Or is it perhaps a wrapper on alloca which would allocate
on the stack and have the same problem?
Tom
--
Tom Hughes (th...@cy...)
Software Engineer, Cyberscience Corporation
http://www.cyberscience.com/
|
|
From: Rupert K. <rk...@mu...> - 2004-03-06 10:23:58
|
On Fri, 5 Mar 2004, Steven J. Plimpton wrote: > I couldn't find anything specific in the docs about Fortran, other > than a statement that valgrind works with executables from all > languages, including Fortran. > > But a simple program like this generates no errors or memory leaks > when run under valgrind-2.0.0, whereas the equivalent C code flags > both. The 1st 2 lines are f90; replacing them with the 3rd line is > f77. > > integer, allocatable :: a(:) > allocate(a(100)) > c integer a(100) > > i = 101 > a(i) = 1 > write (6,*) a(i) > end > > Is valgrind not able to catch that kind of error/leak in Fortran? > Seems odd, since allocate is presumably a wrapper on malloc. > > Steve > If I remember correctly, allocatable array have automatic storage class by default, i.e. their allocation status becomes 'undefined' when their scope is left. The compiler will free the associated memory, similar to using alloca() in C or std::vector in C++. Rupert |