Fortran: frontend passes do_subscript leaks gmp memory [PR97345]
Commit Message
Dear all,
the attached obvious patch fixes a memory leak with gmp variables
that are set but apparently (=valgrind) never cleared. No new
testcase as the current testsuite gives enough coverage
(confirmed by trying a faulty version...) and as per discussion
with Steve (see PR).
Committed after regtesting on x86_64-pc-linux-gnu as:
r13-5095-gfec9fc1a17ec44461cee841513f1b6b8ad680fe4
Thanks,
Harald
From fec9fc1a17ec44461cee841513f1b6b8ad680fe4 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Tue, 10 Jan 2023 22:41:17 +0100
Subject: [PATCH] Fortran: frontend passes do_subscript leaks gmp memory
[PR97345]
gcc/fortran/ChangeLog:
PR fortran/97345
* frontend-passes.cc (do_subscript): Clear used gmp variables.
---
gcc/fortran/frontend-passes.cc | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
@@ -2892,7 +2892,12 @@ do_subscript (gfc_expr **e)
cmp = mpz_cmp (do_end, do_start);
if ((sgn > 0 && cmp < 0) || (sgn < 0 && cmp > 0))
- break;
+ {
+ mpz_clear (do_start);
+ mpz_clear (do_end);
+ mpz_clear (do_step);
+ break;
+ }
}
/* May have to correct the end value if the step does not equal
@@ -2965,6 +2970,12 @@ do_subscript (gfc_expr **e)
mpz_clear (val);
}
}
+
+ if (have_do_start)
+ mpz_clear (do_start);
+ if (have_do_end)
+ mpz_clear (do_end);
+ mpz_clear (do_step);
}
}
}
--
2.35.3