]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix assert for who_points_at monitor cmd for an interiorly pointed block
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Wed, 2 Oct 2013 20:59:05 +0000 (20:59 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Wed, 2 Oct 2013 20:59:05 +0000 (20:59 +0000)
* fix the assert
* some better comments
* update test to verify who_points_at behaviour with an interiorly pointed block

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13609

memcheck/mc_include.h
memcheck/mc_leakcheck.c
memcheck/tests/leak_cpp_interior.cpp
memcheck/tests/leak_cpp_interior.stderr.exp
memcheck/tests/leak_cpp_interior.stderr.exp-64bit

index 728e7b8c04c55a956def55b8e23c1cc7cc898d76..46e824d148e2b8f357175eec4c2ba707023ba122 100644 (file)
@@ -513,7 +513,7 @@ typedef
   }
   LeakCheckHeuristic;
 
-// Nr of heuristics.
+// Nr of heuristics, including the LchNone heuristic.
 #define N_LEAK_CHECK_HEURISTICS 4
 
 // Build mask to check or set Heuristic h membership
index 4590a1aef231727671a7a211ffa6e2fec470f4d3..4555a22f0bd65b8a59214682419b2ca8bd095e29 100644 (file)
@@ -1034,7 +1034,11 @@ lc_scan_memory(Addr start, SizeT len, Bool is_prior_definite,
                                      ch->data, addr, pp_heuristic(h));
                         }
                      }
-                     tl_assert (h == N_LEAK_CHECK_HEURISTICS - 1);
+                     // Verify the loop above has properly scanned all heuristics.
+                     // If the below fails, it probably means the LeakCheckHeuristic
+                     // enum is not in sync anymore with the above loop and/or
+                     // with N_LEAK_CHECK_HEURISTICS.
+                     tl_assert (h == N_LEAK_CHECK_HEURISTICS);
                   }
                }
             }
index e2b52aae166d4823eb48054de00caf3626e84c1e..7fd37d5e85feaaa31a2ea3a01d3fb038ba0d1ded 100644 (file)
@@ -1,10 +1,10 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <string>
+#include <sstream>
 #include "../memcheck.h"
 // Derived from test provided by Timur Iskhodzhanov (bug 280271)
 
-
 class MyClass
 { 
 public:
@@ -74,12 +74,18 @@ Ae *ptrACe;
 B *ptrBC;
 A *ptrAC;
 
+char who_points_at_cmd[100];
 
 void doit(void)
 {
   str = "Valgrind"; // interior ptr.
   str2 = str;
   ptr = new MyClass[3]; // interior ptr.
+  
+  // prepare the who_points_at cmd we will run.
+  // Do it here to avoid having ptr or its exterior ptr kept in a register.
+  sprintf(who_points_at_cmd, "who_points_at %p 20", (char*)ptr - sizeof(void*));
+
   ptr2 = new MyClass[0]; // "interior but exterior ptr".
   // ptr2 points after the chunk, is wrongly considered by memcheck as definitely leaked.
 
@@ -109,6 +115,9 @@ int main() {
    fprintf(stderr, "leak_check summary heuristics stdstring\n");
    (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics stdstring");
 
+   // Test the who_points_at when the block is pointed to with an interior ptr.
+   (void) VALGRIND_MONITOR_COMMAND(who_points_at_cmd);
+
    delete [] ptr;
    delete [] ptr2;
    delete ptrBCe;
index 769c00e8d48af348da9435a63dee428b561827b4..deeb4c9216cf5241e82ea1f675e55356c120f450 100644 (file)
@@ -2,8 +2,8 @@
 valgrind output will go to log
 VALGRIND_DO_LEAK_CHECK
 4 bytes in 1 blocks are definitely lost in loss record ... of ...
-   by 0x........: doit() (leak_cpp_interior.cpp:83)
-   by 0x........: main (leak_cpp_interior.cpp:98)
+   by 0x........: doit() (leak_cpp_interior.cpp:89)
+   by 0x........: main (leak_cpp_interior.cpp:104)
 
 LEAK SUMMARY:
    definitely lost: 4 bytes in 1 blocks
@@ -55,6 +55,10 @@ LEAK SUMMARY:
         suppressed: 0 (+0) bytes in 0 (+0) blocks
 To see details of leaked memory, give 'full' arg to leak_check
 
+Searching for pointers pointing in 20 bytes from 0x........
+*0x........ interior points at 4 bytes inside 0x........
+ Address 0x........ is 0 bytes inside data symbol "ptr"
+block at 0x........ considered reachable by ptr 0x........ using newarray heuristic
 destruct MyClass
 destruct MyClass
 destruct MyClass
index 49b2dedd31a280445572f8bdd23458b4aa9bac8d..18b54787b1b226d90e8063d56043eb12b7cba279 100644 (file)
@@ -2,8 +2,8 @@
 valgrind output will go to log
 VALGRIND_DO_LEAK_CHECK
 8 bytes in 1 blocks are definitely lost in loss record ... of ...
-   by 0x........: doit() (leak_cpp_interior.cpp:83)
-   by 0x........: main (leak_cpp_interior.cpp:98)
+   by 0x........: doit() (leak_cpp_interior.cpp:89)
+   by 0x........: main (leak_cpp_interior.cpp:104)
 
 LEAK SUMMARY:
    definitely lost: 8 bytes in 1 blocks
@@ -55,6 +55,10 @@ LEAK SUMMARY:
         suppressed: 0 (+0) bytes in 0 (+0) blocks
 To see details of leaked memory, give 'full' arg to leak_check
 
+Searching for pointers pointing in 20 bytes from 0x........
+*0x........ interior points at 8 bytes inside 0x........
+ Address 0x........ is 0 bytes inside data symbol "ptr"
+block at 0x........ considered reachable by ptr 0x........ using newarray heuristic
 destruct MyClass
 destruct MyClass
 destruct MyClass