diff mbox series

Fix memory leak in selftest::test_expansion_to_rtl

Message ID 1533258863-46623-1-git-send-email-dmalcolm@redhat.com
State New
Headers show
Series Fix memory leak in selftest::test_expansion_to_rtl | expand

Commit Message

David Malcolm Aug. 3, 2018, 1:14 a.m. UTC
"make selftest-valgrind" shows:

187 bytes in 1 blocks are definitely lost in loss record 567 of 669
    at 0x4A081D4: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x1F08260: xcalloc (xmalloc.c:162)
    by 0xB24F32: init_emit() (emit-rtl.c:5843)
    by 0xC10080: prepare_function_start() (function.c:4803)
    by 0xC10254: init_function_start(tree_node*) (function.c:4877)
    by 0x1CDF92A: selftest::test_expansion_to_rtl() (function-tests.c:595)
    by 0x1CE007C: selftest::function_tests_c_tests() (function-tests.c:676)
    by 0x1E010E7: selftest::run_tests() (selftest-run-tests.c:98)
    by 0x1062D1E: toplev::run_self_tests() (toplev.c:2225)
    by 0x1062F40: toplev::main(int, char**) (toplev.c:2303)
    by 0x1E5B90A: main (main.c:39)

The allocation in question is:

  crtl->emit.regno_pointer_align
    = XCNEWVEC (unsigned char, crtl->emit.regno_pointer_align_length);

This patch fixes this leak (and makes the output of
"make selftest-valgrind" clean) by calling free_after_compilation at the
end of the selftest in question.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.

OK for trunk?

gcc/ChangeLog:
	* function-tests.c (selftest::test_expansion_to_rtl): Call
	free_after_compilation.
---
 gcc/function-tests.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Jeff Law Aug. 6, 2018, 3:17 p.m. UTC | #1
On 08/02/2018 07:14 PM, David Malcolm wrote:
> "make selftest-valgrind" shows:
> 
> 187 bytes in 1 blocks are definitely lost in loss record 567 of 669
>     at 0x4A081D4: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
>     by 0x1F08260: xcalloc (xmalloc.c:162)
>     by 0xB24F32: init_emit() (emit-rtl.c:5843)
>     by 0xC10080: prepare_function_start() (function.c:4803)
>     by 0xC10254: init_function_start(tree_node*) (function.c:4877)
>     by 0x1CDF92A: selftest::test_expansion_to_rtl() (function-tests.c:595)
>     by 0x1CE007C: selftest::function_tests_c_tests() (function-tests.c:676)
>     by 0x1E010E7: selftest::run_tests() (selftest-run-tests.c:98)
>     by 0x1062D1E: toplev::run_self_tests() (toplev.c:2225)
>     by 0x1062F40: toplev::main(int, char**) (toplev.c:2303)
>     by 0x1E5B90A: main (main.c:39)
> 
> The allocation in question is:
> 
>   crtl->emit.regno_pointer_align
>     = XCNEWVEC (unsigned char, crtl->emit.regno_pointer_align_length);
> 
> This patch fixes this leak (and makes the output of
> "make selftest-valgrind" clean) by calling free_after_compilation at the
> end of the selftest in question.
> 
> Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
> 
> OK for trunk?
> 
> gcc/ChangeLog:
> 	* function-tests.c (selftest::test_expansion_to_rtl): Call
> 	free_after_compilation.
OK.
jeff
diff mbox series

Patch

diff --git a/gcc/function-tests.c b/gcc/function-tests.c
index 1b5ebf3..196b3a3 100644
--- a/gcc/function-tests.c
+++ b/gcc/function-tests.c
@@ -661,6 +661,7 @@  test_expansion_to_rtl ()
   ASSERT_STR_CONTAINS (dump, ") ;; function \"test_fn\"\n");
 
   free (dump);
+  free_after_compilation (fun);
 }
 
 /* Run all of the selftests within this file.  */