Fortran: fix several front-end memleaks

Message ID trinity-1f1e993f-cafd-47c6-8624-57734824b9bb-1730235611718@trinity-msg-rest-gmx-gmx-live-67cd9ff8f8-s4qbg
State New
Headers
Series Fortran: fix several front-end memleaks |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed

Commit Message

Harald Anlauf Oct. 29, 2024, 9 p.m. UTC
  Dear all,

while looking at the recent testcase gfortran.dg/pr115070.f90 with f951
running under valgrind, I noticed minor front-end memleaks of gfc_expr's
that are probably fallout from a code refactoring, which are fixed by
the attached.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald
  

Comments

Jerry D Oct. 29, 2024, 10:06 p.m. UTC | #1
On 10/29/24 2:00 PM, Harald Anlauf wrote:
> Dear all,
> 
> while looking at the recent testcase gfortran.dg/pr115070.f90 with f951
> running under valgrind, I noticed minor front-end memleaks of gfc_expr's
> that are probably fallout from a code refactoring, which are fixed by
> the attached.
> 
> Regtested on x86_64-pc-linux-gnu.  OK for mainline?
> 
> Thanks,
> Harald
> 

Yes OK for mainline.

Thanks,

Jerry
  
Harald Anlauf Oct. 30, 2024, 10:21 a.m. UTC | #2
Am 29.10.24 um 23:06 schrieb Jerry D:
> On 10/29/24 2:00 PM, Harald Anlauf wrote:
>> Dear all,
>>
>> while looking at the recent testcase gfortran.dg/pr115070.f90 with f951
>> running under valgrind, I noticed minor front-end memleaks of gfc_expr's
>> that are probably fallout from a code refactoring, which are fixed by
>> the attached.
>>
>> Regtested on x86_64-pc-linux-gnu.  OK for mainline?
>>
>> Thanks,
>> Harald
>>
>
> Yes OK for mainline.

Pushed as r15-4774-gb8291710e3a6d9.

Thanks,
Harald

> Thanks,
>
> Jerry
>
  

Patch

From 87aaaf3b8614730d0f7ccfe29ee36f4921cf48d2 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Tue, 29 Oct 2024 21:52:27 +0100
Subject: [PATCH] Fortran: fix several front-end memleaks

gcc/fortran/ChangeLog:

	* trans-expr.cc (gfc_trans_class_init_assign): Free intermediate
	gfc_expr's.
	* trans.cc (get_final_proc_ref): Likewise.
	(get_elem_size): Likewise.
	(gfc_add_finalizer_call): Likewise.
---
 gcc/fortran/trans-expr.cc | 2 ++
 gcc/fortran/trans.cc      | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index ff8cde93ef4..ddbb5ecf068 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -1890,6 +1890,8 @@  gfc_trans_class_init_assign (gfc_code *code)
     }

   gfc_add_expr_to_block (&block, tmp);
+  gfc_free_expr (lhs);
+  gfc_free_expr (rhs);

   return gfc_finish_block (&block);
 }
diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
index 58b93e233a1..1a0ba637058 100644
--- a/gcc/fortran/trans.cc
+++ b/gcc/fortran/trans.cc
@@ -1128,6 +1128,9 @@  get_final_proc_ref (gfc_se *se, gfc_expr *expr, tree class_container)

   if (POINTER_TYPE_P (TREE_TYPE (se->expr)))
     se->expr = build_fold_indirect_ref_loc (input_location, se->expr);
+
+  if (expr->ts.type != BT_DERIVED && !using_class_container)
+    gfc_free_expr (final_wrapper);
 }


@@ -1155,6 +1158,7 @@  get_elem_size (gfc_se *se, gfc_expr *expr, tree class_container)

       gfc_conv_expr (se, class_size);
       gcc_assert (se->post.head == NULL_TREE);
+      gfc_free_expr (class_size);
     }
 }

@@ -1467,6 +1471,7 @@  gfc_add_finalizer_call (stmtblock_t *block, gfc_expr *expr2,

   gfc_add_expr_to_block (block, tmp);
   gfc_add_block_to_block (block, &final_se.post);
+  gfc_free_expr (expr);

   return true;
 }
--
2.35.3