[PATCH, committed] fortran: Fix minor memleak with GMP variables

Harald Anlauf <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
Dear all,

I pushed the attached obvious patch to plug minor frontend memleaks
with GMP variables introduced at r16-8564 and found with valgrind
as r17-3302-g038a334a1f5d28.

Thanks,
Harald
0001-fortran-Fix-minor-memleak-with-GMP-variables.patch (text/x-patch, 1.4 KB)
From 038a334a1f5d28163393c15c842b4db729028a31 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <[email protected]>
Date: Fri, 14 Aug 2026 21:32:05 +0200
Subject: [PATCH] fortran: Fix minor memleak with GMP variables

Commit r16-8564 introduced code that does not clear used GMP variables.
Fix this.

gcc/fortran/ChangeLog:

	* frontend-passes.cc (inner_loop_may_be_skipped): Clear GMP variables.
---
 gcc/fortran/frontend-passes.cc | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc
index f32d055c061..85cf7ff1394 100644
--- a/gcc/fortran/frontend-passes.cc
+++ b/gcc/fortran/frontend-passes.cc
@@ -2791,13 +2791,21 @@ inner_loop_may_be_skipped (int loop_index, gfc_symbol *outer_sym, mpz_t outer_va
 	  return true;
 	}
 
-      if (!evaluate_loop_bound (loop->ext.iterator->start, outer_sym, outer_val, do_start)
-	  || !evaluate_loop_bound (loop->ext.iterator->end, outer_sym, outer_val, do_end))
+      if (!evaluate_loop_bound (loop->ext.iterator->start, outer_sym, outer_val,
+				do_start))
 	{
 	  mpz_clear (do_step);
 	  return true;
 	}
 
+      if (!evaluate_loop_bound (loop->ext.iterator->end, outer_sym, outer_val,
+				do_end))
+	{
+	  mpz_clear (do_start);
+	  mpz_clear (do_step);
+	  return true;
+	}
+
       cmp = mpz_cmp (do_end, do_start);
       mpz_clear (do_start);
       mpz_clear (do_end);
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.