* [Bug fortran/108923] memory leak of get_intrinsic_dummy_arg result
2023-02-24 12:28 [Bug fortran/108923] New: memory leak of get_intrinsic_dummy_arg result rguenth at gcc dot gnu.org
@ 2023-02-24 16:38 ` mikael at gcc dot gnu.org
2023-02-24 19:41 ` mikael at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-02-24 16:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108923
Mikael Morin <mikael at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mikael at gcc dot gnu.org
Last reconfirmed| |2023-02-24
CC| |mikael at gcc dot gnu.org
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
--- Comment #1 from Mikael Morin <mikael at gcc dot gnu.org> ---
I'm the culprit I guess.
Should be easy to fix anyway.
Taking.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/108923] memory leak of get_intrinsic_dummy_arg result
2023-02-24 12:28 [Bug fortran/108923] New: memory leak of get_intrinsic_dummy_arg result rguenth at gcc dot gnu.org
2023-02-24 16:38 ` [Bug fortran/108923] " mikael at gcc dot gnu.org
@ 2023-02-24 19:41 ` mikael at gcc dot gnu.org
2023-02-24 19:42 ` mikael at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-02-24 19:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108923
--- Comment #2 from Mikael Morin <mikael at gcc dot gnu.org> ---
(In reply to Mikael Morin from comment #1)
> Should be easy to fix anyway.
Not that easy after all.
The following (obvious) fix regresses heavily.
diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index c295721b9d6..73ee50e385c 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -545,6 +545,7 @@ gfc_free_actual_arglist (gfc_actual_arglist *a1)
a2 = a1->next;
if (a1->expr)
gfc_free_expr (a1->expr);
+ free (a1->associated_dummy);
free (a1);
a1 = a2;
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/108923] memory leak of get_intrinsic_dummy_arg result
2023-02-24 12:28 [Bug fortran/108923] New: memory leak of get_intrinsic_dummy_arg result rguenth at gcc dot gnu.org
2023-02-24 16:38 ` [Bug fortran/108923] " mikael at gcc dot gnu.org
2023-02-24 19:41 ` mikael at gcc dot gnu.org
@ 2023-02-24 19:42 ` mikael at gcc dot gnu.org
2023-02-24 21:14 ` cvs-commit at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-02-24 19:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108923
--- Comment #3 from Mikael Morin <mikael at gcc dot gnu.org> ---
Here is a small reproducer by the way:
program p
implicit none
call s(0)
contains
subroutine s(i)
integer :: i
end subroutine s
end program p
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/108923] memory leak of get_intrinsic_dummy_arg result
2023-02-24 12:28 [Bug fortran/108923] New: memory leak of get_intrinsic_dummy_arg result rguenth at gcc dot gnu.org
` (2 preceding siblings ...)
2023-02-24 19:42 ` mikael at gcc dot gnu.org
@ 2023-02-24 21:14 ` cvs-commit at gcc dot gnu.org
2023-02-24 21:44 ` anlauf at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-24 21:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108923
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Mikael Morin <mikael@gcc.gnu.org>:
https://gcc.gnu.org/g:24c9edfa73632276d7698c103f35833f29804d98
commit r13-6337-g24c9edfa73632276d7698c103f35833f29804d98
Author: Mikael Morin <mikael@gcc.gnu.org>
Date: Fri Feb 24 22:11:17 2023 +0100
fortran: Plug leak of associated_dummy memory. [PR108923]
This fixes a memory leak by accompanying the release of
gfc_actual_arglist elements' memory with a release of the
associated_dummy field memory (if allocated).
Actual argument copy is adjusted as well so that each copy can free
its field independently.
PR fortran/108923
gcc/fortran/ChangeLog:
* expr.cc (gfc_free_actual_arglist): Free associated_dummy
memory.
(gfc_copy_actual_arglist): Make a copy of the associated_dummy
field if it is set in the original element.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/108923] memory leak of get_intrinsic_dummy_arg result
2023-02-24 12:28 [Bug fortran/108923] New: memory leak of get_intrinsic_dummy_arg result rguenth at gcc dot gnu.org
` (3 preceding siblings ...)
2023-02-24 21:14 ` cvs-commit at gcc dot gnu.org
@ 2023-02-24 21:44 ` anlauf at gcc dot gnu.org
2023-02-25 20:38 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-02-24 21:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108923
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |anlauf at gcc dot gnu.org
--- Comment #5 from anlauf at gcc dot gnu.org ---
At r13-6337-g24c9edfa73632276d7698c103f35833f29804d98 is still get for
testcase
gcc/testsuite/gfortran.dg/predcom-1.f
==2885== 32 bytes in 2 blocks are definitely lost in loss record 8 of 354
==2885== at 0x4C39571: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2885== by 0x2077B44: xcalloc (xmalloc.c:164)
==2885== by 0x90FE52: get_intrinsic_dummy_arg (intrinsic.cc:4265)
==2885== by 0x90FE52: sort_actual(char const*, gfc_actual_arglist**,
gfc_intrinsic_arg*, locus*) (intrinsic.cc:4433)
==2885== by 0x9100E8: check_specific(gfc_intrinsic_sym*, gfc_expr*, int)
(intrinsic.cc:4774)
==2885== by 0x918D29: gfc_intrinsic_func_interface(gfc_expr*, int)
(intrinsic.cc:5032)
==2885== by 0x97DB9D: resolve_generic_f0 (resolve.cc:2772)
==2885== by 0x97DB9D: resolve_generic_f (resolve.cc:2789)
==2885== by 0x97DB9D: resolve_function (resolve.cc:3347)
==2885== by 0x97DB9D: gfc_resolve_expr(gfc_expr*) [clone .part.0]
(resolve.cc:7211)
==2885== by 0x980B4F: gfc_resolve_expr (resolve.cc:7177)
==2885== by 0x980B4F: resolve_operator(gfc_expr*) (resolve.cc:4092)
==2885== by 0x97BC57: gfc_resolve_expr(gfc_expr*) [clone .part.0]
(resolve.cc:7204)
==2885== by 0x985AF8: gfc_resolve_expr (resolve.cc:7177)
==2885== by 0x985AF8: gfc_resolve_code(gfc_code*, gfc_namespace*)
(resolve.cc:12011)
==2885== by 0x989425: gfc_resolve_blocks(gfc_code*, gfc_namespace*)
(resolve.cc:10996)
==2885== by 0x985AAD: gfc_resolve_code(gfc_code*, gfc_namespace*)
(resolve.cc:11997)
==2885== by 0x98921D: resolve_codes(gfc_namespace*) (resolve.cc:17670)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/108923] memory leak of get_intrinsic_dummy_arg result
2023-02-24 12:28 [Bug fortran/108923] New: memory leak of get_intrinsic_dummy_arg result rguenth at gcc dot gnu.org
` (4 preceding siblings ...)
2023-02-24 21:44 ` anlauf at gcc dot gnu.org
@ 2023-02-25 20:38 ` cvs-commit at gcc dot gnu.org
2023-03-03 14:03 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-25 20:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108923
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Mikael Morin <mikael@gcc.gnu.org>:
https://gcc.gnu.org/g:5c638095e7e0fa4de4e4f7326384a86830b25732
commit r13-6346-g5c638095e7e0fa4de4e4f7326384a86830b25732
Author: Mikael Morin <mikael@gcc.gnu.org>
Date: Sat Feb 25 21:37:46 2023 +0100
fortran: Reuse associated_dummy memory if previously allocated [PR108923]
This avoids making the associted_dummy field point to a new memory chunk
if it's already pointing somewhere, in which case doing so would leak the
previously allocated chunk.
PR fortran/108923
gcc/fortran/ChangeLog:
* intrinsic.cc (get_intrinsic_dummy_arg,
set_intrinsic_dummy_arg): Rename the former to the latter.
Remove the return value, add a reference to the lhs as argument,
and do the pointer assignment inside the function. Don't do
it if the pointer is already non-NULL.
(sort_actual): Update caller.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/108923] memory leak of get_intrinsic_dummy_arg result
2023-02-24 12:28 [Bug fortran/108923] New: memory leak of get_intrinsic_dummy_arg result rguenth at gcc dot gnu.org
` (5 preceding siblings ...)
2023-02-25 20:38 ` cvs-commit at gcc dot gnu.org
@ 2023-03-03 14:03 ` rguenth at gcc dot gnu.org
2023-03-12 10:48 ` cvs-commit at gcc dot gnu.org
2023-03-12 10:48 ` cvs-commit at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-03 14:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108923
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Building the benchmark set fprate_any_fortran of SPEC CPU 2017 there's no leak
from an allocation in get_intrinsic_dummy_arg anymore.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/108923] memory leak of get_intrinsic_dummy_arg result
2023-02-24 12:28 [Bug fortran/108923] New: memory leak of get_intrinsic_dummy_arg result rguenth at gcc dot gnu.org
` (6 preceding siblings ...)
2023-03-03 14:03 ` rguenth at gcc dot gnu.org
@ 2023-03-12 10:48 ` cvs-commit at gcc dot gnu.org
2023-03-12 10:48 ` cvs-commit at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-12 10:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108923
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Mikael Morin
<mikael@gcc.gnu.org>:
https://gcc.gnu.org/g:cd65c727fd6d5a252964dbeb3a735daa0a521a89
commit r12-9243-gcd65c727fd6d5a252964dbeb3a735daa0a521a89
Author: Mikael Morin <mikael@gcc.gnu.org>
Date: Fri Feb 24 22:11:17 2023 +0100
fortran: Plug leak of associated_dummy memory. [PR108923]
This fixes a memory leak by accompanying the release of
gfc_actual_arglist elements' memory with a release of the
associated_dummy field memory (if allocated).
Actual argument copy is adjusted as well so that each copy can free
its field independently.
PR fortran/108923
gcc/fortran/ChangeLog:
* expr.cc (gfc_free_actual_arglist): Free associated_dummy
memory.
(gfc_copy_actual_arglist): Make a copy of the associated_dummy
field if it is set in the original element.
(cherry picked from commit 24c9edfa73632276d7698c103f35833f29804d98)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/108923] memory leak of get_intrinsic_dummy_arg result
2023-02-24 12:28 [Bug fortran/108923] New: memory leak of get_intrinsic_dummy_arg result rguenth at gcc dot gnu.org
` (7 preceding siblings ...)
2023-03-12 10:48 ` cvs-commit at gcc dot gnu.org
@ 2023-03-12 10:48 ` cvs-commit at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-12 10:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108923
--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Mikael Morin
<mikael@gcc.gnu.org>:
https://gcc.gnu.org/g:7b0c9631ccb492c4457a91dbb91e7a5bcd0bc2a6
commit r12-9244-g7b0c9631ccb492c4457a91dbb91e7a5bcd0bc2a6
Author: Mikael Morin <mikael@gcc.gnu.org>
Date: Sat Feb 25 21:37:46 2023 +0100
fortran: Reuse associated_dummy memory if previously allocated [PR108923]
This avoids making the associted_dummy field point to a new memory chunk
if it's already pointing somewhere, in which case doing so would leak the
previously allocated chunk.
PR fortran/108923
gcc/fortran/ChangeLog:
* intrinsic.cc (get_intrinsic_dummy_arg,
set_intrinsic_dummy_arg): Rename the former to the latter.
Remove the return value, add a reference to the lhs as argument,
and do the pointer assignment inside the function. Don't do
it if the pointer is already non-NULL.
(sort_actual): Update caller.
(cherry picked from commit 5c638095e7e0fa4de4e4f7326384a86830b25732)
^ permalink raw reply [flat|nested] 10+ messages in thread