From: Philippe Waroquiers Date: Wed, 2 Oct 2013 20:59:05 +0000 (+0000) Subject: Fix assert for who_points_at monitor cmd for an interiorly pointed block X-Git-Tag: svn/VALGRIND_3_9_0~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa45410976f37a818be9ba9c5a468b2160cc036f;p=thirdparty%2Fvalgrind.git Fix assert for who_points_at monitor cmd for an interiorly pointed block * 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 --- diff --git a/memcheck/mc_include.h b/memcheck/mc_include.h index 728e7b8c04..46e824d148 100644 --- a/memcheck/mc_include.h +++ b/memcheck/mc_include.h @@ -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 diff --git a/memcheck/mc_leakcheck.c b/memcheck/mc_leakcheck.c index 4590a1aef2..4555a22f0b 100644 --- a/memcheck/mc_leakcheck.c +++ b/memcheck/mc_leakcheck.c @@ -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); } } } diff --git a/memcheck/tests/leak_cpp_interior.cpp b/memcheck/tests/leak_cpp_interior.cpp index e2b52aae16..7fd37d5e85 100644 --- a/memcheck/tests/leak_cpp_interior.cpp +++ b/memcheck/tests/leak_cpp_interior.cpp @@ -1,10 +1,10 @@ #include #include #include +#include #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; diff --git a/memcheck/tests/leak_cpp_interior.stderr.exp b/memcheck/tests/leak_cpp_interior.stderr.exp index 769c00e8d4..deeb4c9216 100644 --- a/memcheck/tests/leak_cpp_interior.stderr.exp +++ b/memcheck/tests/leak_cpp_interior.stderr.exp @@ -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 diff --git a/memcheck/tests/leak_cpp_interior.stderr.exp-64bit b/memcheck/tests/leak_cpp_interior.stderr.exp-64bit index 49b2dedd31..18b54787b1 100644 --- a/memcheck/tests/leak_cpp_interior.stderr.exp-64bit +++ b/memcheck/tests/leak_cpp_interior.stderr.exp-64bit @@ -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