|
From: Bill H. <bil...@ki...> - 2009-12-22 15:25:32
|
If you have a program that uses fork and exec and the exec fails and you
call _exit, then valgrind reports all memory used as leaks. Here is a
simple test case:
foo.c:
#include <stdlib.h>
#include <unistd.h>
int main()
{
void* v = malloc(10);
int pid = fork();
if(pid == 0)
{
#ifdef LEAK
_exit(1);
#endif
}
free(v);
return 0;
}
gcc -DLEAK foo.c
valgrind -q --leak-check=full --show-reachable=yes -v ./a.out
HEAP SUMMARY:
==22620== in use at exit: 10 bytes in 1 blocks
==22620== total heap usage: 1 allocs, 0 frees, 10 bytes allocated
==22620==
==22620== 10 bytes in 1 blocks are still reachable in loss record 1 of 1
==22620== at 0x4C221A7: malloc (vg_replace_malloc.c:195)
==22620== by 0x4005DD: main (in
/home/hoffman/MyBuilds/CMake-nighly-build/a.out)
==22620==
gcc foo.c
valgrind -q --leak-check=full --show-reachable=yes -v ./a.out
==22664== HEAP SUMMARY:
==22664== in use at exit: 0 bytes in 0 blocks
==22664== total heap usage: 1 allocs, 1 frees, 10 bytes allocated
--
Bill Hoffman
Kitware, Inc.
28 Corporate Drive
Clifton Park, NY 12065
bil...@ki...
http://www.kitware.com
518 881-4905 (Direct)
518 371-3971 x105
Fax (518) 371-4573
|
|
From: Bill H. <bil...@ki...> - 2009-12-22 14:15:44
|
Bill Hoffman wrote: > If you have a program that uses fork and exec and the exec fails and you > call _exit, then valgrind reports all memory used as leaks. Here is a > simple test case: > > RTFM.... --child-silent-after-fork=yes seems to be the option I was missing. Sorry for the noise. -Bill |