On 10/09/2017 10:38 AM, Benjamin Morgan wrote:
I am using Google Test's EXPECT_EXIT() to sandbox my code in a separate process
on my x86_64 Ubuntu machine and I'm trying to check if there are any memory
leaks in my code. To verify that memory leaks can be detected I created a dummy
test below:
void leaky_function(void)
{
int* sub_proc_leak = (int*) malloc(1000);
}
TEST(my_test_case, memory_leak)
{
EXPECT_EXIT({
leaky_function();
exit(0);
}, ::testing::ExitedWithCode(0),"");
}
There is only one call to leaky_function() in the above code.
I'm compiling it using cmake/make to link in google test with the binary being
called mem_leak_test.
I'm then running it with:
$ valgrind -v --trace-children=yes --tool=memcheck --leak-check=full
--show-leak-kinds=all ./mem_leak_test
I would expect that it would detect 2000 bytes lost, or somehow indicate that
1000 bytes were lost in the subprocess launched by EXPECT_EXIT() and another in
the main process.
However, the LEAK summary only indicates 1000 bytes lost total:
==64382== LEAK SUMMARY:
==64382== definitely lost: 1,000 bytes in 1 blocks
and if I comment out the second call to leaky_function() it will indicate 0
bytes lost.
Please show the exact code after commenting out the second call. (The original
post has no second call.)
--
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users