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

            Bug ID: 86481
           Summary: Memory leak with nested source allocations
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: townsend at astro dot wisc.edu
  Target Milestone: ---

Created attachment 44380
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44380&action=edit
Example program showing the leak

I've come across a memory leak with gfortran 7.2.0 (running on Gentoo Linux
x86_64), that seems somehow to be related to nested sourced allocations (at
least, that's what I've been able to determine). I attach a simple test case
that demonstrates the problem. Compile this with

gfortran -O2 -g -o simple_leak simple_leak.f90

Then, running valgrind:

valgrind --leak-check=full ./simple_leak

...I get the following output:

==11555== Memcheck, a memory error detector
==11555== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==11555== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==11555== Command: ./simple_leak
==11555== 
==11555== 
==11555== HEAP SUMMARY:
==11555==     in use at exit: 89,600 bytes in 400 blocks
==11555==   total heap usage: 515 allocs, 115 frees, 133,468 bytes allocated
==11555== 
==11555== 44,800 (4,800 direct, 40,000 indirect) bytes in 100 blocks are
definitely lost in loss record 4 of 4
==11555==    at 0x4C29BFD: malloc (vg_replace_malloc.c:299)
==11555==    by 0x4006CC: func_foo (simple_leak.f90:44)
==11555==    by 0x4006CC: func_bar (simple_leak.f90:33)
==11555==    by 0x4006CC: simple_leak (simple_leak.f90:23)
==11555==    by 0x4006CC: main (simple_leak.f90:22)
==11555== 
==11555== LEAK SUMMARY:
==11555==    definitely lost: 4,800 bytes in 100 blocks
==11555==    indirectly lost: 40,000 bytes in 100 blocks
==11555==      possibly lost: 0 bytes in 0 blocks
==11555==    still reachable: 44,800 bytes in 200 blocks
==11555==         suppressed: 0 bytes in 0 blocks
==11555== Reachable blocks (those to which a pointer was found) are not shown.
==11555== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==11555== 
==11555== For counts of detected and suppressed errors, rerun with: -v
==11555== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

>From a bit of playing around, it seems the error may be related to the fact
that I'm doing a pair of nested sourced allocations -- one allocation (in
func_bar) has an expression for the SOURCE argument that involves a second
sourced allocation (in func_foo).

cheers,

Rich

Reply via email to