This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, Fortran, committed] free gfc_code of EXEC_END_PROCEDURE


Dear Thomas, dear all,

On 08/22/2012 07:28 AM, Thomas Koenig wrote:
Am 22.08.2012 00:26, schrieb Tobias Burnus:

I think we should join in an try to remove some leakage - and try to not
introduce new ones.

What about using C++ constructors/destructors that allocate/deallocate the necessary memory? This should simplify the code for memory allocation a lot.

I don't see how. GCC operates on lists - and the main problem is to keep track about them to free them when they aren't needed. Only when the scope is limited, it could help to free pointer components; still, one needs to be careful whether the same pointer is used elsewhere.


If you have time, maybe you are able to find out why the following program leaks memory:

!subroutine foo()
  call bar()
contains
  subroutine bar()
  end subroutine bar
end

It doesn't if one comments in the "subroutine foo()" line. According to valgrind, the memory is allocated in parse_contained:
gfc_current_ns = gfc_get_namespace (parent_ns, 1);
However, my impression is that the namespace for ST_END_PROGRAM is properly freed in that function ("gfc_free_namespace (ns);") and the rest (namespace for MAIN__ and its contained "bar" namespace) is properly freed via translate_all_program_units's call to gfc_done_2 which calls gfc_symbol_done_2 and in turn gfc_free_namespace.



For completeness, the valgrind output is as follows:


==6949== 2,976 (2,432 direct, 544 indirect) bytes in 1 blocks are definitely lost in loss record 354 of 369
==6949== at 0x4C292B8: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==6949== by 0xE6AA08: xcalloc (xmalloc.c:162)
==6949== by 0x5EFC7E: gfc_get_namespace(gfc_namespace*, int) (symbol.c:2325)
==6949== by 0x5C14AB: parse_contained(int) (parse.c:3995)
==6949== by 0x5C143E: parse_progunit(gfc_statement) (parse.c:4190)
==6949== by 0x5C1F4D: gfc_parse_file() (parse.c:4595)
==6949== by 0x5FE215: gfc_be_parse_file() (f95-lang.c:191)
==6949== by 0x97B15B: compile_file() (toplev.c:546)
==6949== by 0x97CD19: toplev_main(int, char**) (toplev.c:1863)
==6949== by 0x5F5D454: (below main) (libc-start.c:226)


Tobias


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]