}
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
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);
}
}
}
#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:
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.
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;
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
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
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
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