[Patch, fortran] PR51976 - [F2003] Support deferred-length character components of derived types (allocatable string length)
Steve Kargl
sgk@troutmask.apl.washington.edu
Sun Mar 9 16:44:00 GMT 2014
On Sun, Mar 09, 2014 at 08:38:28AM -0700, W Spector wrote:
>
> 3.) My example in comment #12 appears to work fine. However when
> running the example under valgrind, memory leaks are indicated. I cut
> the example down quite a bit, and it seems that there are leaks
> regardless of whether derived types are used or not. So this isn't a
> regression due to this patch, but something that has been around for a
> while:
>
> wws@w6ws-4:~/fortran/strings$ cat deflen_test5.f90
> program strings
> implicit none
>
> character(:), allocatable :: string
>
> string = "first string"
> print *, string
> string = "second string"
> print *, string
> string = "3rd string"
> print *, string
deallocate(string) ! Fix valgrind
> end program
>
> wws@w6ws-4:~/fortran/strings$ valgrind --leak-check=full a.out
(elided)
> first string
> second string
> 3rd string
> ==3153==
> ==3153== HEAP SUMMARY:
> ==3153== in use at exit: 10 bytes in 1 blocks
> ==3153== total heap usage: 24 allocs, 23 frees, 11,851 bytes allocated
> ==3153==
> ==3153== 10 bytes in 1 blocks are definitely lost in loss record 1 of 1
> ==3153== at 0x4C2B4F0: realloc (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==3153== by 0x400B0E: MAIN__ (in /home/wws/fortran/strings/a.out)
> ==3153== by 0x400C12: main (in /home/wws/fortran/strings/a.out)
> ==3153==
> ==3153== LEAK SUMMARY:
> ==3153== definitely lost: 10 bytes in 1 blocks
> ==3153== indirectly lost: 0 bytes in 0 blocks
> ==3153== possibly lost: 0 bytes in 0 blocks
> ==3153== still reachable: 0 bytes in 0 blocks
> ==3153== suppressed: 0 bytes in 0 blocks
> ==3153==
> ==3153== For counts of detected and suppressed errors, rerun with: -v
> ==3153== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)
% gfc4x -o z b.f90
% valgrind ./z
(elided)
first string
second string
3rd string
==14338==
==14338== HEAP SUMMARY:
==14338== in use at exit: 0 bytes in 0 blocks
==14338== total heap usage: 20 allocs, 20 frees, 2,839 bytes allocated
==14338==
==14338== All heap blocks were freed -- no leaks are possible
==14338==
==14338== For counts of detected and suppressed errors, rerun with: -v
==14338== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
--
Steve
More information about the Fortran
mailing list