]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Changed behaviour of VALGRIND_COUNT_LEAKS slightly. Previously, the numbers it
authorNicholas Nethercote <njn@valgrind.org>
Tue, 22 Jul 2003 22:03:58 +0000 (22:03 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Tue, 22 Jul 2003 22:03:58 +0000 (22:03 +0000)
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

coregrind/docs/coregrind_core.html
memcheck/mac_leakcheck.c
memcheck/mac_needs.c
memcheck/mac_shared.h
memcheck/tests/error_counts.c

index 9f82ec2a3085f581587d8a0b0ce27e16969e5cb8..f459e7520b45abb962786bee64f62337ccfc7a73 100644 (file)
@@ -1017,9 +1017,9 @@ A brief description of the available macros:
     occur.
 <p>
 <li><code>VALGRIND_COUNT_LEAKS</code>: 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 <code>VALGRIND_DO_LEAK_CHECK</code>.
 <p>
 <li><code>VALGRIND_MALLOCLIKE_BLOCK</code>: If your program manages its own
     memory instead of using the standard
index 9ad23601a6a8031555710154181cb905e6ea7633..581d649d3a57e11c1ca3be52e7457afb80579c6f 100644 (file)
@@ -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 );
 }
index e90151e00d8fa3567808a8b371881ff3305fa834..852edb3861cc83e0c30eee78ad6c94d65ca65b23 100644 (file)
@@ -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;
    }
index ffdf83b60fd71b156147faeeb9d53d43fa45a5d9..d11b7ab2346b47248d5e208f23549f3fa357bfd3 100644 (file)
@@ -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                                            ---*/
index 23be977c7bdcbfd8b340e136466d6bb1726adb0e..2cf1060b3d796f10dc87f50a9ef308314b27eb91 100644 (file)
@@ -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 */