|
From:
<mat...@er...> - 2006-11-13 13:26:02
|
Hello Valgrind-Users, I'm trying to understand how to use the option --error-exitcode to make my testcases started from make stop when a memory leak is found. I have a test program written in C that leaks two portions of memory. I run it through valgrind with --error-exitcode=3D1. Valgrind reports the memory leaks, but the exit code is still zero. Am I doing something = wrong or did I misinterpret the meaning of --error-exitcode? I'm using valgrind 3.2.1 on a 64 bit machine running SUSE Linux = Enterprise Server 10. The output from valgrind (and my test program) is found below. Thanks and best regards, Mattias St=E5hlberg c-template/tests> valgrind --error-exitcode=3D1 ./check_hello =3D=3D3973=3D=3D Memcheck, a memory error detector. =3D=3D3973=3D=3D Copyright (C) 2002-2006, and GNU GPL'd, by Julian = Seward et al. =3D=3D3973=3D=3D Using LibVEX rev 1658, a library for dynamic binary = translation. =3D=3D3973=3D=3D Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks = LLP. =3D=3D3973=3D=3D Using valgrind-3.2.1, a dynamic binary instrumentation = framework. =3D=3D3973=3D=3D Copyright (C) 2000-2006, and GNU GPL'd, by Julian = Seward et al. =3D=3D3973=3D=3D For more details, rerun with: -v =3D=3D3973=3D=3D Running suite(s): Hello =3D=3D3974=3D=3D =3D=3D3974=3D=3D ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 3 = from 1) =3D=3D3974=3D=3D malloc/free: in use at exit: 16,720 bytes in 28 blocks. =3D=3D3974=3D=3D malloc/free: 34 allocs, 6 frees, 16,798 bytes = allocated. =3D=3D3974=3D=3D For counts of detected errors, rerun with: -v =3D=3D3974=3D=3D searching for pointers to 28 not-freed blocks. =3D=3D3974=3D=3D checked 58,280 bytes. =3D=3D3974=3D=3D =3D=3D3974=3D=3D LEAK SUMMARY: =3D=3D3974=3D=3D definitely lost: 16,016 bytes in 2 blocks. =3D=3D3974=3D=3D possibly lost: 0 bytes in 0 blocks. =3D=3D3974=3D=3D still reachable: 704 bytes in 26 blocks. =3D=3D3974=3D=3D suppressed: 0 bytes in 0 blocks. =3D=3D3974=3D=3D Use --leak-check=3Dfull to see details of leaked = memory. =3D=3D3975=3D=3D =3D=3D3975=3D=3D ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 3 = from 1) =3D=3D3975=3D=3D malloc/free: in use at exit: 757 bytes in 29 blocks. =3D=3D3975=3D=3D malloc/free: 48 allocs, 19 frees, 1,743 bytes = allocated. =3D=3D3975=3D=3D For counts of detected errors, rerun with: -v =3D=3D3975=3D=3D searching for pointers to 29 not-freed blocks. =3D=3D3975=3D=3D checked 58,340 bytes. =3D=3D3975=3D=3D =3D=3D3975=3D=3D LEAK SUMMARY: =3D=3D3975=3D=3D definitely lost: 0 bytes in 0 blocks. =3D=3D3975=3D=3D possibly lost: 0 bytes in 0 blocks. =3D=3D3975=3D=3D still reachable: 757 bytes in 29 blocks. =3D=3D3975=3D=3D suppressed: 0 bytes in 0 blocks. =3D=3D3975=3D=3D Reachable blocks (those to which a pointer was found) = are not shown. =3D=3D3975=3D=3D To see them, rerun with: --show-reachable=3Dyes 100%: Checks: 2, Failures: 0, Errors: 0 =3D=3D3973=3D=3D =3D=3D3973=3D=3D ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 3 = from 1) =3D=3D3973=3D=3D malloc/free: in use at exit: 0 bytes in 0 blocks. =3D=3D3973=3D=3D malloc/free: 60 allocs, 60 frees, 2,504 bytes = allocated. =3D=3D3973=3D=3D For counts of detected errors, rerun with: -v =3D=3D3973=3D=3D All heap blocks were freed -- no leaks are possible. c-template/tests> echo $? 0 c-template/tests> |
|
From: Olly B. <ol...@su...> - 2006-11-13 15:08:19
|
On 2006-11-13, Mattias Ståhlberg XX <mat...@er...> wrote:
> I'm trying to understand how to use the option --error-exitcode to make
> my testcases started from make stop when a memory leak is found.
I don't think leaks count as errors (at least not for these purposes).
Your best option might be to add this just before the test case exits:
if (RUNNING_ON_VALGRIND) {
VALGRIND_DO_LEAK_CHECK;
long vg_leaks = 0, vg_dubious = 0, vg_reachable = 0, dummy;
VALGRIND_COUNT_LEAKS(vg_leaks, vg_dubious, vg_reachable, dummy);
if (vg_leaks || vg_dubious || vg_reachable) exit(1);
}
You only want to test vg_dubious if you ever hold on to allocated blocks
only by a pointer which isn't to the start. Otherwise it just increases
the small chance that a garbage value will accidentally act as a
reference to a leaked block and hide a leak.
Cheers,
Olly
|