public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] fortran: Plug leak of associated_dummy memory. [PR108923]
@ 2023-02-24 21:21 Mikael Morin
  0 siblings, 0 replies; only message in thread
From: Mikael Morin @ 2023-02-24 21:21 UTC (permalink / raw)
  To: gfortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 203 bytes --]

Hello,

I have just pushed a for PR108923 (a memory leak).
It fixes the small reproducer that I pasted in bugzilla, and I have run 
it through the fortran regression testsuite.
More details in the patch.

[-- Attachment #2: 0001-fortran-Plug-leak-of-associated_dummy-memory.-PR1089.patch --]
[-- Type: text/x-patch, Size: 1521 bytes --]

From 545a7d5da5fcc338e29c5241b574ac99d03f4454 Mon Sep 17 00:00:00 2001
From: Mikael Morin <mikael@gcc.gnu.org>
Date: Fri, 24 Feb 2023 22:11:17 +0100
Subject: [PATCH] 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.
---
 gcc/fortran/expr.cc | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index c295721b9d6..4662328bf31 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;
     }
@@ -565,6 +566,12 @@ gfc_copy_actual_arglist (gfc_actual_arglist *p)
       new_arg = gfc_get_actual_arglist ();
       *new_arg = *p;
 
+      if (p->associated_dummy != NULL)
+	{
+	  new_arg->associated_dummy = gfc_get_dummy_arg ();
+	  *new_arg->associated_dummy = *p->associated_dummy;
+	}
+
       new_arg->expr = gfc_copy_expr (p->expr);
       new_arg->next = NULL;
 
-- 
2.39.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-24 21:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-24 21:21 [pushed] fortran: Plug leak of associated_dummy memory. [PR108923] Mikael Morin

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).