On 03/02/2017 01:08 AM, Richard Biener wrote:
On Thu, Mar 2, 2017 at 2:01 AM, Joseph Myers <jos...@codesourcery.com> wrote:
On Wed, 1 Mar 2017, Martin Sebor wrote:

Joseph, since you commented on the bug, do you have a suggestion
for a different site for it or a guard?  The only other call to
the function is in the Fortran FE and it's neither guarded nor
does it appear to ever be called.

I don't think a guard is needed.  Arguably it should be called from an
atexit handler, but since we don't have such a handler calling it from the
relevant pass seems reasonable (and I'm not sure what the right way to
handle such freeing of memory in the JIT context is).

IMHO we should call it from gcc::~context

Thanks, that makes sense to me.  The attached patch does that.

Martin
PR tree-optimization/79699 - small memory leak in MPFR

gcc/ChangeLog:

	PR tree-optimization/79699
	* context.c (context::~context): Free MPFR caches to avoid
	a memory leak on program exit.

diff --git a/gcc/context.c b/gcc/context.c
index a7ded9c..d2009b9 100644
--- a/gcc/context.c
+++ b/gcc/context.c
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "context.h"
 #include "pass_manager.h"
 #include "dumpfile.h"
+#include "mpfr.h"
 
 /* The singleton holder of global state: */
 gcc::context *g;
@@ -42,4 +43,7 @@ gcc::context::~context ()
 {
   delete m_passes;
   delete m_dumps;
+
+  /* Release MPFR caches to avoid Valgrind leak reports.  */
+  mpfr_free_cache ();
 }

Reply via email to