http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40850

Mikael Morin <mikael at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mikael at gcc dot gnu.org

--- Comment #12 from Mikael Morin <mikael at gcc dot gnu.org> 2011-02-21 
12:57:31 UTC ---
(In reply to comment #11)
> I don't know whether it fixes comment 0 or comment 4
>
Sorry, I forgot to precise. 
It fixes neither. 
More precisely for comments 0 and 4, it does fix a read of freed memory:

==82785== Invalid read of size 8
==82785==    at 0x400F21: __mod_all_MOD_add (in
/usr/home/mik/gfortran/pr40850/comment_0)
==82785==    by 0x4023D9: MAIN__ (in /usr/home/mik/gfortran/pr40850/comment_0)
==82785==    by 0x402703: main (in /usr/home/mik/gfortran/pr40850/comment_0)
==82785==  Address 0x14be678 is 8 bytes inside a block of size 112 free'd

but doesn't fix a double free affecting comments 0, 4 and 8:

==82785== Invalid free() / delete / delete[]
==82785==    at 0x25A37E: free (in
/usr/local/lib/valgrind/vgpreload_memcheck-amd64-freebsd.so)
==82785==    by 0x402609: MAIN__ (in /usr/home/mik/gfortran/pr40850/comment_0)
==82785==    by 0x402703: main (in /usr/home/mik/gfortran/pr40850/comment_0)
==82785==  Address 0x14be3d0 is 0 bytes inside a block of size 8 free'd



Comment 8 is not affected by the invalid read as the containing entity is not
allocatable, hence not explicitly freed at the end. Thus, components release
can't happen before containing entity's release. 

For the remaining double free, the temporary for the array constructor is
filled using simple copies, and thus has components pointing to the original
array. Those components are freed by the temporary array cleanup, and again
during the final release of all allocatables. 
One could fix it by not freeing the temporary's components (no deep/nested
free), but I have the feeling (haven't completely made my mind about it) that
the proper fix, in the general case, is to create nested temporaries and do
deep copies. And yes, that would be horribly expensive :-(.

Reply via email to