This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Possible memory problem in allocations
- From: "François-Xavier Coudert" <fxcoudert at gmail dot com>
- To: GFortran <fortran at gcc dot gnu dot org>
- Date: Fri, 5 May 2006 12:20:50 +0200
- Subject: Possible memory problem in allocations
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=l568eKbVwImDnE+AkruqAy3BLI0xLYARru/nf0sRPy7jC4tLYzr4r+ATUrrEF8aGF2PqClrJVN1b4O05tfp2lJbuhc2iYVK+5QiiK0MjG9z5xNsB0l1+1MW1aD+4EoVFmQi/hamRmksHBq2YSpmONXlhHcpeu7wkm8zetYjo/us=
Hi all,
I experienced a surprising segfault in my latests experiments of CP2K,
a large chemistry code that makes wide use of all possible F95
constructs :)
I can reduce it to the following example, which does not segfault (the
original segfault only appears with a magic combination of options and
array sizes, during full moon) but shows errors when run inside
valgrind:
TYPE foo
INTEGER, DIMENSION(:), POINTER :: array
END TYPE foo
type(foo),allocatable,dimension(:) :: mol
integer :: i, n
n = 10
ALLOCATE (mol(n))
do i = 1, n
ALLOCATE (mol(i)%array(5))
end do
END
Among a bunch of error messages (which may have the same root, but I'm
not sure), there's one that happens also with the original code:
==8319== Conditional jump or move depends on uninitialised value(s)
==8319== at 0x8048DAA: _gfortran_allocate_array (memory.c:246)
==8319== by 0x8048373: MAIN__ (alloc.f90:12)
==8319== by 0x80483F3: main (fmain.c:18)
My questions are: is the reduced code correct? Whose responsability is
it to NULLIFY the "array" components of the "mol" array allocated in
the first ALLOCATE statement: the compiler or the user?
I'm not yet very confortable with all this stuff, so I might just be
talking nonsense. If so, please correct me! :)
Thanks,
FX