[gcc r17-3302] fortran: Fix minor memleak with GMP variables

Harald Anlauf via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:038a334a1f5d28163393c15c842b4db729028a31

commit r17-3302-g038a334a1f5d28163393c15c842b4db729028a31
Author: Harald Anlauf <[email protected]>
Date:   Fri Aug 14 21:32:05 2026 +0200

    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.

Diff:
---
 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 f32d055c0619..85cf7ff13945 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);
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.