This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix memory leaks in gimple-ssa-sprintf.c (PR tree-optimization/79339).
- From: Martin Liška <mliska at suse dot cz>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Martin Sebor <msebor at gmail dot com>
- Date: Thu, 2 Feb 2017 15:30:48 +0100
- Subject: [PATCH] Fix memory leaks in gimple-ssa-sprintf.c (PR tree-optimization/79339).
- Authentication-results: sourceware.org; auth=none
Hi.
As mentioned in the PR, mpfr_clear should be called in order to release memory.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
Ready to be installed?
Martin
>From 627ea01882a2a307b107e5e4aa8de6dc60530a81 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 2 Feb 2017 12:25:32 +0100
Subject: [PATCH] Fix memory leaks in gimple-ssa-sprintf.c (PR
tree-optimization/79339).
gcc/ChangeLog:
2017-02-02 Martin Liska <mliska@suse.cz>
PR tree-optimization/79339
* gimple-ssa-sprintf.c (format_floating_max): Call mpfr_clear.
(format_floating): Likewise.
---
gcc/gimple-ssa-sprintf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c
index 11f41741f95..fe4083ef1e2 100644
--- a/gcc/gimple-ssa-sprintf.c
+++ b/gcc/gimple-ssa-sprintf.c
@@ -1501,7 +1501,10 @@ format_floating_max (tree type, char spec, HOST_WIDE_INT prec)
mpfr_from_real (x, &rv, GMP_RNDN);
/* Return a value one greater to account for the leading minus sign. */
- return 1 + get_mpfr_format_length (x, "", prec, spec, 'D');
+ unsigned HOST_WIDE_INT r
+ = 1 + get_mpfr_format_length (x, "", prec, spec, 'D');
+ mpfr_clear (x);
+ return r;
}
/* Return a range representing the minimum and maximum number of bytes
@@ -1739,6 +1742,7 @@ format_floating (const directive &dir, tree arg)
of the result struct. */
*minmax[i] = get_mpfr_format_length (mpfrval, fmtstr, prec[i],
dir.specifier, rndspec);
+ mpfr_clear (mpfrval);
}
}
--
2.11.0