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]

Possible memory problem in allocations


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


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