diff options
author | David Malcolm <dmalcolm@redhat.com> | 2014-10-03 14:37:53 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2014-10-03 14:37:53 -0400 |
commit | 1f6f361c60da3323a9655bca49859d0f6bf8041a (patch) | |
tree | bedc6e6582203a54226a7aa6394be137b767100e | |
parent | dbfbacdbbf727e8ab3a8cff2d5650d8000de0449 (diff) | |
download | gcc-1f6f361c60da3323a9655bca49859d0f6bf8041a.tar.gz |
Fix memory leak within diagnostic.c
Running e.g. test-factorial.exe under valgrind shows that libgccjit.so
was leaking ~13.5KB of RAM per invocation of the compiler here:
==57074== 21,440 bytes in 4 blocks are definitely lost in loss record 896 of 907
==57074== at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==57074== by 0x58EFFC7: xmalloc (xmalloc.c:147)
==57074== by 0x58A9256: diagnostic_initialize(diagnostic_context*, int) (diagnostic.c:129)
==57074== by 0x4DF6062: toplev::main(int, char**) (toplev.c:1120)
==57074== by 0x4E09E13: gcc::jit::playback::context::compile() (internal-api.c:4987)
==57074== by 0x4E015C2: gcc::jit::recording::context::compile() (internal-api.c:878)
==57074== by 0x401CA4: test_jit (harness.h:188)
==57074== by 0x401D88: main (harness.h:230)
==57074==
==57074== 34,112 (256 direct, 33,856 indirect) bytes in 4 blocks are definitely lost in loss record 902 of 907
==57074== at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==57074== by 0x58EFFC7: xmalloc (xmalloc.c:147)
==57074== by 0x58A91D4: diagnostic_initialize(diagnostic_context*, int) (diagnostic.c:122)
==57074== by 0x4DF6062: toplev::main(int, char**) (toplev.c:1120)
==57074== by 0x4E09E13: gcc::jit::playback::context::compile() (internal-api.c:4987)
==57074== by 0x4E015C2: gcc::jit::recording::context::compile() (internal-api.c:878)
==57074== by 0x401CA4: test_jit (harness.h:188)
==57074== by 0x401D88: main (harness.h:230)
Fix it.
gcc/ChangeLog.jit:
* diagnostic.c (diagnostic_finish): Free the memory for
context->classify_diagnostic and context->printer, running the
destructor for the latter.
-rw-r--r-- | gcc/diagnostic.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index b1b63660a2c..642cbe38b9a 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -177,6 +177,15 @@ diagnostic_finish (diagnostic_context *context) } diagnostic_file_cache_fini (); + + XDELETEVEC (context->classify_diagnostic); + context->classify_diagnostic = NULL; + + /* diagnostic_initialize allocates context->printer using XNEW + and placement-new. */ + context->printer->~pretty_printer (); + XDELETE (context->printer); + context->printer = NULL; } /* Initialize DIAGNOSTIC, where the message MSG has already been |