}
};
-int main() {
- std::string str = "Valgrind"; // interior ptr.
- std::string str2 = str;
- MyClass *ptr = new MyClass[3]; // interior ptr.
- MyClass *ptr2 = new MyClass[0]; // "interior but exterior ptr".
- // ptr2 points after the chunk, is wrongly considered by memcheck as definitely leaked.
+std::string str;
+std::string str2;
+MyClass *ptr;
+MyClass *ptr2;
+Be *ptrBCe;
+Ae *ptrACe;
+B *ptrBC;
+A *ptrAC;
+
- Be *ptrBCe = new Ce; // interior ptr.
- Ae *ptrACe = new Ce; // not an interior pointer.
- B *ptrBC = new C; // interior ptr.
- A *ptrAC = new C; // not an interior pointer.
+void doit(void)
+{
+ str = "Valgrind"; // interior ptr.
+ str2 = str;
+ ptr = new MyClass[3]; // interior ptr.
+ ptr2 = new MyClass[0]; // "interior but exterior ptr".
+ // ptr2 points after the chunk, is wrongly considered by memcheck as definitely leaked.
+ ptrBCe = new Ce; // interior ptr.
+ ptrACe = new Ce; // not an interior pointer.
+ ptrBC = new C; // interior ptr.
+ ptrAC = new C; // not an interior pointer.
+
+
+ str2 += " rocks (str2)\n"; // interior ptr.
+}
- str2 += " rocks (str2)\n"; // interior ptr.
+int main() {
+
+ doit();
VALGRIND_MONITOR_COMMAND("v.set log_output");
fprintf(stderr, "VALGRIND_DO_LEAK_CHECK\n");
valgrind output will go to log
VALGRIND_DO_LEAK_CHECK
4 bytes in 1 blocks are definitely lost in loss record ... of ...
- by 0x........: main (leak_cpp_interior.cpp:72)
+ by 0x........: doit() (leak_cpp_interior.cpp:83)
+ by 0x........: main (leak_cpp_interior.cpp:98)
LEAK SUMMARY:
definitely lost: 4 bytes in 1 blocks
valgrind output will go to log
VALGRIND_DO_LEAK_CHECK
8 bytes in 1 blocks are definitely lost in loss record ... of ...
- by 0x........: main (leak_cpp_interior.cpp:72)
+ by 0x........: doit() (leak_cpp_interior.cpp:83)
+ by 0x........: main (leak_cpp_interior.cpp:98)
LEAK SUMMARY:
definitely lost: 8 bytes in 1 blocks