public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/58058] New: Memory leak with transfer function
@ 2013-08-02 11:35 thomas.jourdan at orange dot fr
2013-08-02 14:18 ` [Bug fortran/58058] [4.7/4.8/4.9 Regression] " janus at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: thomas.jourdan at orange dot fr @ 2013-08-02 11:35 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58058
Bug ID: 58058
Summary: Memory leak with transfer function
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: thomas.jourdan at orange dot fr
Hello,
Using gfortran 4.8.1, the following code runs fine but according to valgrind it
produces a memory leak:
program test1
implicit none
integer, dimension(3) :: t1, t2
character(len=64) :: str
t1 = (/1,2,3/)
!str = transfer((/1,2,3/),str) ! works
str = transfer(t1,str) ! memory leak
t2 = transfer(str,t1)
write(*,*) 't2 = ',t2
end program test1
The output is:
==7005== Memcheck, a memory error detector
==7005== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==7005== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==7005== Command: ./test1
==7005==
t2 = 1 2 3
==7005==
==7005== HEAP SUMMARY:
==7005== in use at exit: 64 bytes in 1 blocks
==7005== total heap usage: 23 allocs, 22 frees, 11,897 bytes allocated
==7005==
==7005== LEAK SUMMARY:
==7005== definitely lost: 64 bytes in 1 blocks
==7005== indirectly lost: 0 bytes in 0 blocks
==7005== possibly lost: 0 bytes in 0 blocks
==7005== still reachable: 0 bytes in 0 blocks
==7005== suppressed: 0 bytes in 0 blocks
==7005== Rerun with --leak-check=full to see details of leaked memory
==7005==
==7005== For counts of detected and suppressed errors, rerun with: -v
==7005== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
If I use directly "str = transfer((/1,2,3/),str)" instead, no memory problem
occurs. I experienced the same problem with the following test:
program test2
implicit none
type tuple
integer :: nn
integer :: pp
integer :: qq
end type tuple
character(len=64) :: str
type(tuple) :: mt1, mt2
mt1%nn = 1
mt1%pp = 2
mt1%qq = 3
str = transfer(mt1,str)
mt2 = transfer(str,mt2)
end program test2
Thanks,
Thomas
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/58058] [4.7/4.8/4.9 Regression] Memory leak with transfer function
2013-08-02 11:35 [Bug fortran/58058] New: Memory leak with transfer function thomas.jourdan at orange dot fr
@ 2013-08-02 14:18 ` janus at gcc dot gnu.org
2013-08-02 15:02 ` janus at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2013-08-02 14:18 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58058
janus at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-08-02
CC| |janus at gcc dot gnu.org,
| |pault at gcc dot gnu.org
Summary|Memory leak with transfer |[4.7/4.8/4.9 Regression]
|function |Memory leak with transfer
| |function
Ever confirmed|0 |1
--- Comment #1 from janus at gcc dot gnu.org ---
I can confirm the leak with gfortran versions 4.7, 4.8 and trunk. However,
there is no leak in 4.3, so it is a regression (haven't tried other versions).
Indeed the dump produced by -fdump-tree-original shows a __builtin_malloc,
which is never freed. The regression seems to be due to this commit:
http://gcc.gnu.org/viewcvs/gcc?view=revision&revision=143462
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/58058] [4.7/4.8/4.9 Regression] Memory leak with transfer function
2013-08-02 11:35 [Bug fortran/58058] New: Memory leak with transfer function thomas.jourdan at orange dot fr
2013-08-02 14:18 ` [Bug fortran/58058] [4.7/4.8/4.9 Regression] " janus at gcc dot gnu.org
@ 2013-08-02 15:02 ` janus at gcc dot gnu.org
2013-08-02 16:12 ` janus at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2013-08-02 15:02 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58058
--- Comment #2 from janus at gcc dot gnu.org ---
I think the following should be enough to fix it:
Index: gcc/fortran/trans-intrinsic.c
===================================================================
--- gcc/fortran/trans-intrinsic.c (revision 201331)
+++ gcc/fortran/trans-intrinsic.c (working copy)
@@ -5652,8 +5652,7 @@ scalar_transfer:
if (expr->ts.type == BT_CHARACTER)
{
- tree direct;
- tree indirect;
+ tree direct, indirect, free;
ptr = convert (gfc_get_pchar_type (expr->ts.kind), source);
tmpdecl = gfc_create_var (gfc_get_pchar_type (expr->ts.kind),
@@ -5686,6 +5685,13 @@ scalar_transfer:
tmp = build3_v (COND_EXPR, tmp, direct, indirect);
gfc_add_expr_to_block (&se->pre, tmp);
+ /* Free the temporary string, if necessary. */
+ free = gfc_call_free (tmpdecl);
+ tmp = fold_build2_loc (input_location, GT_EXPR, boolean_type_node,
+ dest_word_len, source_bytes);
+ tmp = build3_v (COND_EXPR, tmp, free, build_empty_stmt
(input_location));
+ gfc_add_expr_to_block (&se->post, tmp);
+
se->expr = tmpdecl;
se->string_length = fold_convert (gfc_charlen_type_node, dest_word_len);
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/58058] [4.7/4.8/4.9 Regression] Memory leak with transfer function
2013-08-02 11:35 [Bug fortran/58058] New: Memory leak with transfer function thomas.jourdan at orange dot fr
2013-08-02 14:18 ` [Bug fortran/58058] [4.7/4.8/4.9 Regression] " janus at gcc dot gnu.org
2013-08-02 15:02 ` janus at gcc dot gnu.org
@ 2013-08-02 16:12 ` janus at gcc dot gnu.org
2013-08-09 17:10 ` janus at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2013-08-02 16:12 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58058
janus at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |janus at gcc dot gnu.org
--- Comment #3 from janus at gcc dot gnu.org ---
(In reply to janus from comment #2)
> I think the following should be enough to fix it:
It also regtests cleanly.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/58058] [4.7/4.8/4.9 Regression] Memory leak with transfer function
2013-08-02 11:35 [Bug fortran/58058] New: Memory leak with transfer function thomas.jourdan at orange dot fr
` (2 preceding siblings ...)
2013-08-02 16:12 ` janus at gcc dot gnu.org
@ 2013-08-09 17:10 ` janus at gcc dot gnu.org
2013-08-11 11:32 ` janus at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2013-08-09 17:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58058
--- Comment #4 from janus at gcc dot gnu.org ---
Fixed on trunk with this commit:
Author: janus
Date: Fri Aug 9 16:57:58 2013
New Revision: 201633
URL: http://gcc.gnu.org/viewcvs?rev=201633&root=gcc&view=rev
Log:
2013-08-09 Janus Weil <janus@gcc.gnu.org>
PR fortran/58058
* trans-intrinsic.c (gfc_conv_intrinsic_transfer): Free the temporary
string, if necessary.
2013-08-09 Janus Weil <janus@gcc.gnu.org>
PR fortran/58058
* gfortran.dg/transfer_intrinsic_6.f90: New.
Added:
trunk/gcc/testsuite/gfortran.dg/transfer_intrinsic_6.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/trans-intrinsic.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/58058] [4.7/4.8/4.9 Regression] Memory leak with transfer function
2013-08-02 11:35 [Bug fortran/58058] New: Memory leak with transfer function thomas.jourdan at orange dot fr
` (3 preceding siblings ...)
2013-08-09 17:10 ` janus at gcc dot gnu.org
@ 2013-08-11 11:32 ` janus at gcc dot gnu.org
2013-08-11 14:10 ` janus at gcc dot gnu.org
2013-08-11 14:15 ` janus at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2013-08-11 11:32 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58058
--- Comment #5 from janus at gcc dot gnu.org ---
Fixed on 4.8 with:
Author: janus
Date: Sun Aug 11 11:31:41 2013
New Revision: 201652
URL: http://gcc.gnu.org/viewcvs?rev=201652&root=gcc&view=rev
Log:
2013-08-11 Janus Weil <janus@gcc.gnu.org>
Backport from trunk:
2013-08-09 Janus Weil <janus@gcc.gnu.org>
PR fortran/58058
* trans-intrinsic.c (gfc_conv_intrinsic_transfer): Free the temporary
string, if necessary.
2013-08-11 Janus Weil <janus@gcc.gnu.org>
Backport from trunk:
2013-08-09 Janus Weil <janus@gcc.gnu.org>
PR fortran/58058
* gfortran.dg/transfer_intrinsic_6.f90: New.
Added:
branches/gcc-4_8-branch/gcc/testsuite/gfortran.dg/transfer_intrinsic_6.f90
Modified:
branches/gcc-4_8-branch/gcc/fortran/ChangeLog
branches/gcc-4_8-branch/gcc/fortran/trans-intrinsic.c
branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/58058] [4.7/4.8/4.9 Regression] Memory leak with transfer function
2013-08-02 11:35 [Bug fortran/58058] New: Memory leak with transfer function thomas.jourdan at orange dot fr
` (4 preceding siblings ...)
2013-08-11 11:32 ` janus at gcc dot gnu.org
@ 2013-08-11 14:10 ` janus at gcc dot gnu.org
2013-08-11 14:15 ` janus at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2013-08-11 14:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58058
--- Comment #6 from janus at gcc dot gnu.org ---
Fixed on 4.7 with:
Author: janus
Date: Sun Aug 11 14:08:12 2013
New Revision: 201653
URL: http://gcc.gnu.org/viewcvs?rev=201653&root=gcc&view=rev
Log:
2013-08-11 Janus Weil <janus@gcc.gnu.org>
Backport from trunk:
2013-08-09 Janus Weil <janus@gcc.gnu.org>
PR fortran/58058
* trans-intrinsic.c (gfc_conv_intrinsic_transfer): Free the temporary
string, if necessary.
2013-08-11 Janus Weil <janus@gcc.gnu.org>
Backport from trunk:
2013-08-09 Janus Weil <janus@gcc.gnu.org>
PR fortran/58058
* gfortran.dg/transfer_intrinsic_6.f90: New.
Added:
branches/gcc-4_7-branch/gcc/testsuite/gfortran.dg/transfer_intrinsic_6.f90
Modified:
branches/gcc-4_7-branch/gcc/fortran/ChangeLog
branches/gcc-4_7-branch/gcc/fortran/trans-intrinsic.c
branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/58058] [4.7/4.8/4.9 Regression] Memory leak with transfer function
2013-08-02 11:35 [Bug fortran/58058] New: Memory leak with transfer function thomas.jourdan at orange dot fr
` (5 preceding siblings ...)
2013-08-11 14:10 ` janus at gcc dot gnu.org
@ 2013-08-11 14:15 ` janus at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2013-08-11 14:15 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58058
janus at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #7 from janus at gcc dot gnu.org ---
Fixed on all active branches. Closing.
Thanks for the report!
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-08-11 14:15 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-02 11:35 [Bug fortran/58058] New: Memory leak with transfer function thomas.jourdan at orange dot fr
2013-08-02 14:18 ` [Bug fortran/58058] [4.7/4.8/4.9 Regression] " janus at gcc dot gnu.org
2013-08-02 15:02 ` janus at gcc dot gnu.org
2013-08-02 16:12 ` janus at gcc dot gnu.org
2013-08-09 17:10 ` janus at gcc dot gnu.org
2013-08-11 11:32 ` janus at gcc dot gnu.org
2013-08-11 14:10 ` janus at gcc dot gnu.org
2013-08-11 14:15 ` janus 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).