From: Mikael Morin <morin-mikael@orange.fr>
To: gfortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Cc: Harald Anlauf <anlauf@gmx.de>
Subject: fortran: Reuse associated_dummy memory if previously allocated [PR108923]
Date: Sat, 25 Feb 2023 17:35:04 +0100 [thread overview]
Message-ID: <48878e99-0ecb-3688-0c2e-db7ec69856df@orange.fr> (raw)
[-- Attachment #1: Type: text/plain, Size: 738 bytes --]
Hello,
Harald found a testcase with memory still leaking despite my previous
patch for PR108923.
That patch was fixing a leak caused by absence of memory release, the
attached patch fixes a leak caused by pointer overwrite.
I haven't investigated why sort_actual is called several times( which
causes the memory leak) nor tried to avoid that. Theoretically, one
could assert that the previous associated_dummy value is the same as the
one to be written (it should be the same at each sort_actual
invocation), but I have preferred to silently overwrite, and fix just
the memory problem.
Manually tested on Harald's testcase (predcom-1.f) and ran the full
fortran testsuite on x86_64-pc-linux-gnu.
OK for master and 12 and 11?
[-- Attachment #2: 0001-fortran-Reuse-associated_dummy-memory-if-previously-.patch --]
[-- Type: text/x-patch, Size: 1762 bytes --]
From 9b88208ec4130712d33d5c7ed74fc17466624a0c Mon Sep 17 00:00:00 2001
From: Mikael Morin <mikael@gcc.gnu.org>
Date: Sat, 25 Feb 2023 16:27:24 +0100
Subject: [PATCH] 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.
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.
---
gcc/fortran/intrinsic.cc | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/gcc/fortran/intrinsic.cc b/gcc/fortran/intrinsic.cc
index 17ee999c3b9..e69e541efe0 100644
--- a/gcc/fortran/intrinsic.cc
+++ b/gcc/fortran/intrinsic.cc
@@ -4259,15 +4259,14 @@ remove_nullargs (gfc_actual_arglist **ap)
}
-static gfc_dummy_arg *
-get_intrinsic_dummy_arg (gfc_intrinsic_arg *intrinsic)
+static void
+set_intrinsic_dummy_arg (gfc_dummy_arg *&dummy_arg, gfc_intrinsic_arg *intrinsic)
{
- gfc_dummy_arg * const dummy_arg = gfc_get_dummy_arg ();
+ if (dummy_arg == NULL)
+ dummy_arg = gfc_get_dummy_arg ();
dummy_arg->intrinsicness = GFC_INTRINSIC_DUMMY_ARG;
dummy_arg->u.intrinsic = intrinsic;
-
- return dummy_arg;
}
@@ -4430,7 +4429,7 @@ do_sort:
if (a == NULL)
a = gfc_get_actual_arglist ();
- a->associated_dummy = get_intrinsic_dummy_arg (f);
+ set_intrinsic_dummy_arg (a->associated_dummy, f);
if (actual == NULL)
*ap = a;
--
2.39.1
next reply other threads:[~2023-02-25 16:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-25 16:35 Mikael Morin [this message]
2023-02-25 17:20 ` Harald Anlauf
2023-02-25 18:08 ` Mikael Morin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48878e99-0ecb-3688-0c2e-db7ec69856df@orange.fr \
--to=morin-mikael@orange.fr \
--cc=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).