[Patch, Fortran] PR fortran/40850 derived type allocatables freed before their components
Mikael Morin
mikael.morin@sfr.fr
Tue Feb 22 15:01:00 GMT 2011
On Tuesday 22 February 2011 14:31:07 Dominique Dhumieres wrote:
> > ... The question is how big is enough (1024 * 1024 in the test), ...
>
> Well, I have tried 1024*1024*1024. This eats all the 4Gb on my laptop
> without finishing to run (I lost patience after one hour) w and w/o the
> patch.
>
> Dominique
Sorry, I wasn't very clear, it seems.
There is a memory problem without the patch in that one tries to free a's
components after a itself has been freed.
This should generate a segmentation violation if the memory is given back to
the operating system as soon as free is called.
This is however not necessarily the case, depending on the malloc/free
implementation which may retain small memory chunks freed as a cache for
subsequent malloc calls.
In that case the invalid access will not trigger as the OS still sees the
memory chunk as used by the program, which will finish successfully.
I'm assuming however, that if the memory chunk is big enough, the libc memory
manager will decide to really release it, thus making the bug noticeable.
This is the case on FreeBSD.
The purpose is not however to try to allocate something so big that the test
fails early at the malloc call.
As type(t) contains an allocatable, and thus has the size of an array
descriptor (well above 4 bytes), it is not surprising that allocating a chunk
of 1G type(t) structs brings your machine on its knees.
I'm looking for a value triggering failure on most common platforms, yet small
enough for the testsuite ; I suppose that if it doesn't fail for a few dozens
millions, it won't ever fail, so no need to bother any more. If you have tried
a few other values between 1M and 1G, and it doesn't fail for those values,
then let's not care about Darwin.
I think we have committed memory fixing patches without testcase in the past,
as those bugs can be hard to detect. We could do the same here, but I would
like a test if possible. It is useful only if the test can trigger.
Mikael
More information about the Fortran
mailing list