Uh oh, this is embarrassing, but apparently I failed to read the output
correctly.  I used the "--log-file=valgrind_mem_leak_%p" to separate the
parent and child process logs by PID, and IT WAS detecting the leak in the
subprocess. (This is an awesome feature btw!!!)I was just missed it before
because I didn't pay enough attention to the PIDs in the logs. Also, the
final leak summary doesn't aggregate the leaked subprocess memory with the
parent process' leaked memory so I thought it wasn't detecting it. Sorry
for spamming the list =/

TL;DR: It is actually doing what I expect, I just failed to read the
results properly.

Sorry again,

~Benjamin

On Mon, Oct 9, 2017 at 12:53 PM, John Reiser <jrei...@bitwagon.com> wrote:

> 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
>



-- 
Benjamin Morgan
University of Washington
Electrical Engineering
bmorg...@uw.edu
425.652.9094
------------------------------------------------------------------------------
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

Reply via email to