From: Nicholas Nethercote Date: Tue, 22 Jul 2003 22:03:58 +0000 (+0000) Subject: Changed behaviour of VALGRIND_COUNT_LEAKS slightly. Previously, the numbers it X-Git-Tag: svn/VALGRIND_2_0_0~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aca466757fda8ae4160443e377e05afae747b4e2;p=thirdparty%2Fvalgrind.git Changed behaviour of VALGRIND_COUNT_LEAKS slightly. Previously, the numbers it returned (bytes leaked, dubious, etc) were incremented for every leak check performed. So if you called VALGRIND_DO_LEAK_CHECK twice in a row, the totals would be updated twice by the same amount. This was a bit silly. So now COUNT_LEAKS just returns the numbers of bytes leaked found from the previous leak check. I even updated the docs, and changed the regression test so old version fail but the new version passes (by doing two DO_LEAK_CHECKS in a row). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1778 --- diff --git a/coregrind/docs/coregrind_core.html b/coregrind/docs/coregrind_core.html index 9f82ec2a30..f459e7520b 100644 --- a/coregrind/docs/coregrind_core.html +++ b/coregrind/docs/coregrind_core.html @@ -1017,9 +1017,9 @@ A brief description of the available macros: occur.

  • VALGRIND_COUNT_LEAKS: fills in the four arguments with - the number of bytes of memory found by all previous leak checks that - were leaked, dubious, reachable and suppressed. Again, useful for - test harness code. + the number of bytes of memory found by the previous leak check to + be leaked, dubious, reachable and suppressed. Again, useful in + test harness code, after calling VALGRIND_DO_LEAK_CHECK.

  • VALGRIND_MALLOCLIKE_BLOCK: If your program manages its own memory instead of using the standard diff --git a/memcheck/mac_leakcheck.c b/memcheck/mac_leakcheck.c index 9ad23601a6..581d649d3a 100644 --- a/memcheck/mac_leakcheck.c +++ b/memcheck/mac_leakcheck.c @@ -356,10 +356,10 @@ void MAC_(pp_LeakError)(void* vl, UInt n_this_record, UInt n_total_records) VG_(pp_ExeContext)(l->allocated_at); } -Int MAC_(total_bytes_leaked) = 0; -Int MAC_(total_bytes_dubious) = 0; -Int MAC_(total_bytes_reachable) = 0; -Int MAC_(total_bytes_suppressed) = 0; +Int MAC_(bytes_leaked) = 0; +Int MAC_(bytes_dubious) = 0; +Int MAC_(bytes_reachable) = 0; +Int MAC_(bytes_suppressed) = 0; /* Top level entry point to leak detector. Call here, passing in suitable address-validating functions (see comment at top of @@ -376,10 +376,10 @@ void MAC_(do_detect_memory_leaks) ( ) { Int i; - Int blocks_leaked, bytes_leaked; - Int blocks_dubious, bytes_dubious; - Int blocks_reachable, bytes_reachable; - Int blocks_suppressed, bytes_suppressed; + Int blocks_leaked; + Int blocks_dubious; + Int blocks_reachable; + Int blocks_suppressed; Int n_lossrecords; UInt bytes_notified; Bool is_suppressed; @@ -457,10 +457,10 @@ void MAC_(do_detect_memory_leaks) ( } /* Print out the commoned-up blocks and collect summary stats. */ - blocks_leaked = bytes_leaked = 0; - blocks_dubious = bytes_dubious = 0; - blocks_reachable = bytes_reachable = 0; - blocks_suppressed = bytes_suppressed = 0; + blocks_leaked = MAC_(bytes_leaked) = 0; + blocks_dubious = MAC_(bytes_dubious) = 0; + blocks_reachable = MAC_(bytes_reachable) = 0; + blocks_suppressed = MAC_(bytes_suppressed) = 0; for (i = 0; i < n_lossrecords; i++) { Bool print_record; @@ -488,20 +488,20 @@ void MAC_(do_detect_memory_leaks) ( /*allow_GDB_attach*/False, /*count_error*/False ); if (is_suppressed) { - blocks_suppressed += p_min->num_blocks; - bytes_suppressed += p_min->total_bytes; + blocks_suppressed += p_min->num_blocks; + MAC_(bytes_suppressed) += p_min->total_bytes; - } else if (Unreached == p_min->loss_mode) { - blocks_leaked += p_min->num_blocks; - bytes_leaked += p_min->total_bytes; + } else if (Unreached == p_min->loss_mode) { + blocks_leaked += p_min->num_blocks; + MAC_(bytes_leaked) += p_min->total_bytes; - } else if (Interior == p_min->loss_mode) { - blocks_dubious += p_min->num_blocks; - bytes_dubious += p_min->total_bytes; + } else if (Interior == p_min->loss_mode) { + blocks_dubious += p_min->num_blocks; + MAC_(bytes_dubious) += p_min->total_bytes; - } else if (Proper == p_min->loss_mode) { - blocks_reachable += p_min->num_blocks; - bytes_reachable += p_min->total_bytes; + } else if (Proper == p_min->loss_mode) { + blocks_reachable += p_min->num_blocks; + MAC_(bytes_reachable) += p_min->total_bytes; } else { VG_(skin_panic)("generic_detect_memory_leaks: unknown loss mode"); @@ -512,13 +512,13 @@ void MAC_(do_detect_memory_leaks) ( VG_(message)(Vg_UserMsg, ""); VG_(message)(Vg_UserMsg, "LEAK SUMMARY:"); VG_(message)(Vg_UserMsg, " definitely lost: %d bytes in %d blocks.", - bytes_leaked, blocks_leaked ); + MAC_(bytes_leaked), blocks_leaked ); VG_(message)(Vg_UserMsg, " possibly lost: %d bytes in %d blocks.", - bytes_dubious, blocks_dubious ); + MAC_(bytes_dubious), blocks_dubious ); VG_(message)(Vg_UserMsg, " still reachable: %d bytes in %d blocks.", - bytes_reachable, blocks_reachable ); + MAC_(bytes_reachable), blocks_reachable ); VG_(message)(Vg_UserMsg, " suppressed: %d bytes in %d blocks.", - bytes_suppressed, blocks_suppressed ); + MAC_(bytes_suppressed), blocks_suppressed ); if (!MAC_(clo_show_reachable)) { VG_(message)(Vg_UserMsg, "Reachable blocks (those to which a pointer was found) are not shown."); @@ -527,11 +527,6 @@ void MAC_(do_detect_memory_leaks) ( } VG_(message)(Vg_UserMsg, ""); - MAC_(total_bytes_leaked) += bytes_leaked; - MAC_(total_bytes_dubious) += bytes_dubious; - MAC_(total_bytes_reachable) += bytes_reachable; - MAC_(total_bytes_suppressed) += bytes_suppressed; - VG_(free) ( lc_shadows ); VG_(free) ( lc_reachedness ); } diff --git a/memcheck/mac_needs.c b/memcheck/mac_needs.c index e90151e00d..852edb3861 100644 --- a/memcheck/mac_needs.c +++ b/memcheck/mac_needs.c @@ -801,10 +801,12 @@ Bool MAC_(handle_common_client_requests)(ThreadState* tst, UInt* arg, switch (arg[0]) { case VG_USERREQ__COUNT_LEAKS: { /* count leaked bytes */ UInt** argp = (UInt**)arg; - *argp[1] = MAC_(total_bytes_leaked); - *argp[2] = MAC_(total_bytes_dubious); - *argp[3] = MAC_(total_bytes_reachable); - *argp[4] = MAC_(total_bytes_suppressed); + // MAC_(bytes_leaked) et al were set by the last leak check (or zero + // if no prior leak checks performed). + *argp[1] = MAC_(bytes_leaked); + *argp[2] = MAC_(bytes_dubious); + *argp[3] = MAC_(bytes_reachable); + *argp[4] = MAC_(bytes_suppressed); *ret = 0; return True; } diff --git a/memcheck/mac_shared.h b/memcheck/mac_shared.h index ffdf83b60f..d11b7ab234 100644 --- a/memcheck/mac_shared.h +++ b/memcheck/mac_shared.h @@ -274,10 +274,10 @@ extern Bool (*MAC_(check_noaccess))( Addr a, UInt len, Addr* bad_addr ); extern Bool (*MAC_(describe_addr_supp)) ( Addr a, AddrInfo* ai ); /* For VALGRIND_COUNT_LEAKS client request */ -extern Int MAC_(total_bytes_leaked); -extern Int MAC_(total_bytes_dubious); -extern Int MAC_(total_bytes_reachable); -extern Int MAC_(total_bytes_suppressed); +extern Int MAC_(bytes_leaked); +extern Int MAC_(bytes_dubious); +extern Int MAC_(bytes_reachable); +extern Int MAC_(bytes_suppressed); /*------------------------------------------------------------*/ /*--- Functions ---*/ diff --git a/memcheck/tests/error_counts.c b/memcheck/tests/error_counts.c index 23be977c7b..2cf1060b3d 100644 --- a/memcheck/tests/error_counts.c +++ b/memcheck/tests/error_counts.c @@ -40,6 +40,7 @@ int main(void) reachable = malloc(99); + VALGRIND_DO_LEAK_CHECK; VALGRIND_DO_LEAK_CHECK; VALGRIND_COUNT_LEAKS(n_leaked, n_dubious, n_reachable, n_suppressed); if (n_reachable == 147) n_reachable = 99; /* handle glibc differences */