public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug fortran/46487] New: allocatable scalars leak memory (allocatable_scalar_5.f90) @ 2010-11-15 15:53 burnus at gcc dot gnu.org 2010-11-16 13:54 ` [Bug fortran/46487] " burnus at gcc dot gnu.org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: burnus at gcc dot gnu.org @ 2010-11-15 15:53 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46487 Summary: allocatable scalars leak memory (allocatable_scalar_5.f90) Product: gcc Version: 4.6.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned@gcc.gnu.org ReportedBy: burnus@gcc.gnu.org CC: janus@gcc.gnu.org Blocks: 46485 The program allocatable_scalar_5.f90 leaks memory - even with the following patch applied. Valgrind shows: LEAK SUMMARY: definitely lost: 8 bytes in 2 blocks One finds twice: 4 bytes in 1 blocks are definitely lost in loss record 1 of 2 at 0x4C26C36: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x400ACE: func.1538 (allocatable_scalar_5.f90:36) by 0x4008D1: MAIN__ (allocatable_scalar_5.f90:15) by 0x400B40: main (allocatable_scalar_5.f90:27) where the crucial lines are: 34 if (allocated (func)) call abort () 35 if (alloc) then 36 allocate(func) 37 func = 5332 Note: The following patch is needed for the test case to make it valid; cf. PR 46484 diff --git a/gcc/testsuite/gfortran.dg/allocatable_scalar_5.f90 b/gcc/testsuite/gfortran.dg/allocatable_scalar_5.f90 index cee95a1..efa40e9 100644 --- a/gcc/testsuite/gfortran.dg/allocatable_scalar_5.f90 +++ b/gcc/testsuite/gfortran.dg/allocatable_scalar_5.f90 @@ -3,3 +3,3 @@ ! -! PR fortran/41872 +! PR fortran/41872; updated due to PR fortran/46484 ! @@ -13,4 +13,2 @@ program test if (allocated (a)) call abort () - if (allocated (func (.false.))) call abort () - if (.not.allocated (func (.true.))) call abort () b = 7 @@ -30,3 +28,2 @@ program test - if (allocated (func2 ())) call abort () contains @@ -43,6 +40,2 @@ contains - function func2 () - integer, allocatable :: func2 - end function func2 - subroutine intout (dum, alloc) ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug fortran/46487] allocatable scalars leak memory (allocatable_scalar_5.f90) 2010-11-15 15:53 [Bug fortran/46487] New: allocatable scalars leak memory (allocatable_scalar_5.f90) burnus at gcc dot gnu.org @ 2010-11-16 13:54 ` burnus at gcc dot gnu.org 2013-06-26 17:52 ` [Bug fortran/46487] Missing memory freeing for functions returning allocatable scalars (allocatable_scalar_5.f90) dominiq at lps dot ens.fr 2013-08-25 14:47 ` burnus at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: burnus at gcc dot gnu.org @ 2010-11-16 13:54 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46487 --- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2010-11-16 13:49:58 UTC --- Well, the problem is actually simple: program test implicit none integer :: b b = func() contains function func () integer, allocatable :: func allocate(func) func = 5332 end function func end program test The function "func" returns the allocatable scalar as: return __result_func; In the main program, one has: b = *func (); or - if "b" is allocatable: *b = *func () However, the proper method should be: { tmp = func() b = *tmp free (tmp); } (Or replace: "free (tmp)" by "if (tmp != NULL) free(tmp)", which is identical as free also accepts NULL.) For arrays, it currently works without this detour as there the argument is passed by value; doing likewise for allocatable scalars would be one -- ABI breaking -- alternative. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug fortran/46487] Missing memory freeing for functions returning allocatable scalars (allocatable_scalar_5.f90) 2010-11-15 15:53 [Bug fortran/46487] New: allocatable scalars leak memory (allocatable_scalar_5.f90) burnus at gcc dot gnu.org 2010-11-16 13:54 ` [Bug fortran/46487] " burnus at gcc dot gnu.org @ 2013-06-26 17:52 ` dominiq at lps dot ens.fr 2013-08-25 14:47 ` burnus at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: dominiq at lps dot ens.fr @ 2013-06-26 17:52 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46487 Dominique d'Humieres <dominiq at lps dot ens.fr> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2013-06-26 Ever confirmed|0 |1 --- Comment #2 from Dominique d'Humieres <dominiq at lps dot ens.fr> --- Still present at revision 200429. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug fortran/46487] Missing memory freeing for functions returning allocatable scalars (allocatable_scalar_5.f90) 2010-11-15 15:53 [Bug fortran/46487] New: allocatable scalars leak memory (allocatable_scalar_5.f90) burnus at gcc dot gnu.org 2010-11-16 13:54 ` [Bug fortran/46487] " burnus at gcc dot gnu.org 2013-06-26 17:52 ` [Bug fortran/46487] Missing memory freeing for functions returning allocatable scalars (allocatable_scalar_5.f90) dominiq at lps dot ens.fr @ 2013-08-25 14:47 ` burnus at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: burnus at gcc dot gnu.org @ 2013-08-25 14:47 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46487 Tobias Burnus <burnus at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |DUPLICATE --- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> --- Mark as duplicate of PR55603 - even if this PR is older. *** This bug has been marked as a duplicate of bug 55603 *** ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-08-25 14:47 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-11-15 15:53 [Bug fortran/46487] New: allocatable scalars leak memory (allocatable_scalar_5.f90) burnus at gcc dot gnu.org 2010-11-16 13:54 ` [Bug fortran/46487] " burnus at gcc dot gnu.org 2013-06-26 17:52 ` [Bug fortran/46487] Missing memory freeing for functions returning allocatable scalars (allocatable_scalar_5.f90) dominiq at lps dot ens.fr 2013-08-25 14:47 ` burnus at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).