Author: philippe
Date: Wed Oct 2 20:59:05 2013
New Revision: 13609
Log:
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
Modified:
trunk/memcheck/mc_include.h
trunk/memcheck/mc_leakcheck.c
trunk/memcheck/tests/leak_cpp_interior.cpp
trunk/memcheck/tests/leak_cpp_interior.stderr.exp
trunk/memcheck/tests/leak_cpp_interior.stderr.exp-64bit
Modified: trunk/memcheck/mc_include.h
==============================================================================
--- trunk/memcheck/mc_include.h (original)
+++ trunk/memcheck/mc_include.h Wed Oct 2 20:59:05 2013
@@ -513,7 +513,7 @@
}
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
Modified: trunk/memcheck/mc_leakcheck.c
==============================================================================
--- trunk/memcheck/mc_leakcheck.c (original)
+++ trunk/memcheck/mc_leakcheck.c Wed Oct 2 20:59:05 2013
@@ -1034,7 +1034,11 @@
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);
}
}
}
Modified: trunk/memcheck/tests/leak_cpp_interior.cpp
==============================================================================
--- trunk/memcheck/tests/leak_cpp_interior.cpp (original)
+++ trunk/memcheck/tests/leak_cpp_interior.cpp Wed Oct 2 20:59:05 2013
@@ -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 @@
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 @@
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;
Modified: trunk/memcheck/tests/leak_cpp_interior.stderr.exp
==============================================================================
--- trunk/memcheck/tests/leak_cpp_interior.stderr.exp (original)
+++ trunk/memcheck/tests/leak_cpp_interior.stderr.exp Wed Oct 2 20:59:05 2013
@@ -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 @@
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
Modified: trunk/memcheck/tests/leak_cpp_interior.stderr.exp-64bit
==============================================================================
--- trunk/memcheck/tests/leak_cpp_interior.stderr.exp-64bit (original)
+++ trunk/memcheck/tests/leak_cpp_interior.stderr.exp-64bit Wed Oct 2 20:59:05 2013
@@ -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 @@
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
|