From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1647) id B523C3858D1E; Sun, 12 Mar 2023 10:48:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B523C3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678618109; bh=Eu0l2Cat1giqdHhlktIqVN+ud4SAJ5kZF+BVkM4Z/LQ=; h=From:To:Subject:Date:From; b=QTW0EsmvFtGlki9OdIi8jxt9HP6K9feTa+Ejof94zK6SQfNQ36tXZzZ10pq1y5uBU zT72LT2uA78nItJWDTpITHKAz1LsYknvhFy+mCl5Y1041WcXhtboyKP/bBDxNF4ErF iUUTeLD2MGyuNoeb4BUZj51n7nXgRuOJ2/pNrQ0A= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Mikael Morin To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-9243] fortran: Plug leak of associated_dummy memory. [PR108923] X-Act-Checkin: gcc X-Git-Author: Mikael Morin X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 18dee4a183ae4e795c9e64df0cc4ab6b8932731a X-Git-Newrev: cd65c727fd6d5a252964dbeb3a735daa0a521a89 Message-Id: <20230312104829.B523C3858D1E@sourceware.org> Date: Sun, 12 Mar 2023 10:48:29 +0000 (GMT) List-Id: https://gcc.gnu.org/g:cd65c727fd6d5a252964dbeb3a735daa0a521a89 commit r12-9243-gcd65c727fd6d5a252964dbeb3a735daa0a521a89 Author: Mikael Morin 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) Diff: --- gcc/fortran/expr.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index 15d41d023d3..1369f25011f 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;