]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Use global vars to point at possibly leaked
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Mon, 30 Sep 2013 21:17:09 +0000 (21:17 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Mon, 30 Sep 2013 21:17:09 +0000 (21:17 +0000)
Depending on the compiler or optimisation level, the blocks that
are supposed to be possibly leaked are still reachable.
=> change the pointers to be global variables,
and do the allocation in a function, not in main.

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

memcheck/tests/leak_cpp_interior.cpp
memcheck/tests/leak_cpp_interior.stderr.exp
memcheck/tests/leak_cpp_interior.stderr.exp-64bit

index e380403308aa4e5097629898b7dff7ed71361e03..ac1850a237bea59081d661ae0b3d588b7db77ef5 100644 (file)
@@ -65,21 +65,37 @@ struct C : public A, public B
    } 
 };
 
-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");
index bbecf9871fb333fba8de3abdf00aef4a9eea2d42..769c00e8d48af348da9435a63dee428b561827b4 100644 (file)
@@ -2,7 +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........: 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
index 72348739cd031f940fa84f94e68ea5bf165286dc..49b2dedd31a280445572f8bdd23458b4aa9bac8d 100644 (file)
@@ -2,7 +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........: 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