https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122863

--- Comment #5 from Steve Kargl <kargl at gcc dot gnu.org> ---
(In reply to anlauf from comment #2)
> ==9673== HEAP SUMMARY:
> ==9673==     in use at exit: 8 bytes in 2 blocks
> ==9673==   total heap usage: 19 allocs, 17 frees, 5,452 bytes allocated
> ==9673== 
> ==9673== 4 bytes in 1 blocks are definitely lost in loss record 2 of 2
> ==9673==    at 0x4841984: malloc (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==9673==    by 0x401471: MAIN__ (pr122863.f90:45)
> ==9673==    by 0x4018EC: main (pr122863.f90:40)
> ==9673== 
> ==9673== LEAK SUMMARY:
> ==9673==    definitely lost: 4 bytes in 1 blocks

AFAICT, the above is leaked memory from the array constructor.
Changing

  items(:) = [item(42)]

to

  items(:) = item(42)

removes this leak.

> ==9673==    indirectly lost: 0 bytes in 0 blocks
> ==9673==      possibly lost: 0 bytes in 0 blocks
> ==9673==    still reachable: 4 bytes in 1 blocks

This is due to the program exiting, where the program
does not do diligent memory handling.  Adding

  if (allocated(items(1)%val)) deallocate(items(1)%val)

before 'end program test' fixes this 'leak'.

> ==9673==         suppressed: 0 bytes in 0 blocks
> ==9673== Reachable blocks (those to which a pointer was found) are not shown.
> ==9673== To see them, rerun with: --leak-check=full --show-leak-kinds=all
> ==9673== 
> ==9673== For lists of detected and suppressed errors, rerun with: -s
> ==9673== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)

Reply via email to