]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add another expected for memcheck/tests/leak_cpp_interior
authorPaul Floyd <pjfloyd@wanadoo.fr>
Fri, 27 May 2022 11:27:58 +0000 (13:27 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Fri, 27 May 2022 11:27:58 +0000 (13:27 +0200)
There is a difference between the outputs when using
32bit and 64bit with clang++/libc++

Running the test in a shell with the output piped through c++filt I see
64bit:
--2153-- operator new[](unsigned long)(32) = 0x55AB040
--2153-- malloc(31) = 0x55AB0A0
--2153-- operator new[](unsigned long)(8) = 0x55AB100
--2153-- operator new(unsigned long)(16) = 0x55AB150
--2153-- operator new(unsigned long)(16) = 0x55AB1A0
--2153-- operator new(unsigned long)(32) = 0x55AB1F0
--2153-- operator new(unsigned long)(32) = 0x55AB250

32bit:
--55024-- operator new[](unsigned int)(28) = 0x7D41030
--55024-- malloc(31) = 0x7D41090
--55024-- operator new[](unsigned int)(4) = 0x7D410F0
--55024-- operator new(unsigned int)(8) = 0x7D41140
--55024-- operator new(unsigned int)(8) = 0x7D41190
--55024-- operator new(unsigned int)(16) = 0x7D411E0
--55024-- operator new(unsigned int)(16) = 0x7D41230
--55024-- operator new(unsigned int)(32) = 0x7D41280

Note the extra 32 byte allocation at the end. This is because of

  str2 += " rocks (str2)\n"; // interior ptr.

at the end of void doit(void)

Details of the mechaism here
https://stackoverflow.com/questions/21694302/what-are-the-mechanics-of-short-string-optimization-in-libc

str2 starts containing 9 characters "Valgrind"
Catenating to it makes it "Valgrind rocks (str2)\n" which is exactly 22 characters.

The 64bit SSO has a capacity of 22 chars, so there is no need to switch from
SSO in the stack variable to using heap allocation.

The 32bit SSO only has a capacity of 10, so there there is space
in the SSO for the initial string but the catenation expands it
beyond the SSO capacity and there is a heap allocation
via the std::basic_string allocator, which calls raw ::operator new.

memcheck/tests/Makefile.am
memcheck/tests/leak_cpp_interior.stderr.exp-freebsd-32bit [new file with mode: 0644]

index eb9487272d360ec31077fa40b4be0151d4ff139f..302006e8bccc6bfada921aa3b60bc82adfdf1ca7 100644 (file)
@@ -366,7 +366,7 @@ EXTRA_DIST = \
        wrapmallocstatic.stderr.exp \
        writev1.stderr.exp writev1.stderr.exp-solaris writev1.vgtest \
        xml1.stderr.exp xml1.stdout.exp xml1.vgtest xml1.stderr.exp-s390x-mvc \
-       leak_cpp_interior.stderr.exp-freebsd
+       leak_cpp_interior.stderr.exp-freebsd leak_cpp_interior.stderr.exp-freebsd-32bit
 
 check_PROGRAMS = \
        accounting \
diff --git a/memcheck/tests/leak_cpp_interior.stderr.exp-freebsd-32bit b/memcheck/tests/leak_cpp_interior.stderr.exp-freebsd-32bit
new file mode 100644 (file)
index 0000000..09037c1
--- /dev/null
@@ -0,0 +1,131 @@
+
+valgrind output will go to log
+VALGRIND_DO_LEAK_CHECK
+x bytes in 1 blocks are definitely lost in loss record ... of ...
+   by 0x........: doit() (leak_cpp_interior.cpp:119)
+   by 0x........: main (leak_cpp_interior.cpp:135)
+
+LEAK SUMMARY:
+   definitely lost: x bytes in 1 blocks
+   indirectly lost: 0 bytes in 0 blocks
+     possibly lost: 0 bytes in 0 blocks
+   still reachable: x bytes in 7 blocks
+                      of which reachable via heuristic:
+                        length64           : x bytes in 1 blocks
+                        newarray           : x bytes in 1 blocks
+                        multipleinheritance: x bytes in 2 blocks
+Reachable blocks (those to which a pointer was found) are not shown.
+To see them, rerun with: --leak-check=full --show-leak-kinds=all
+
+leak_check summary heuristics multipleinheritance
+LEAK SUMMARY:
+   definitely lost: x (+0) bytes in 1 (+0) blocks
+   indirectly lost: 0 (+0) bytes in 0 (+0) blocks
+     possibly lost: x (+x) bytes in 2 (+2) blocks
+   still reachable: x (-x) bytes in 5 (-2) blocks
+                      of which reachable via heuristic:
+                        length64           : 0 (-x) bytes in 0 (-1) blocks
+                        newarray           : 0 (-x) bytes in 0 (-1) blocks
+                        multipleinheritance: x (+0) bytes in 2 (+0) blocks
+To see details of leaked memory, give 'full' arg to leak_check
+
+leak_check summary any heuristics newarray
+LEAK SUMMARY:
+   definitely lost: x (+0) bytes in 1 (+0) blocks
+   indirectly lost: 0 (+0) bytes in 0 (+0) blocks
+     possibly lost: x (-x) bytes in 3 (+1) blocks
+   still reachable: x (+x) bytes in 4 (-1) blocks
+                      of which reachable via heuristic:
+                        newarray           : x (+x) bytes in 1 (+1) blocks
+                        multipleinheritance: 0 (-x) bytes in 0 (-2) blocks
+To see details of leaked memory, give 'full' arg to leak_check
+
+leak_check summary heuristics length64
+LEAK SUMMARY:
+   definitely lost: x (+0) bytes in 1 (+0) blocks
+   indirectly lost: 0 (+0) bytes in 0 (+0) blocks
+     possibly lost: x (-x) bytes in 3 (+0) blocks
+   still reachable: x (+x) bytes in 4 (+0) blocks
+                      of which reachable via heuristic:
+                        length64           : x (+x) bytes in 1 (+1) blocks
+                        newarray           : 0 (-x) bytes in 0 (-1) blocks
+To see details of leaked memory, give 'full' arg to leak_check
+
+leak_check summary heuristics stdstring
+LEAK SUMMARY:
+   definitely lost: x (+0) bytes in 1 (+0) blocks
+   indirectly lost: 0 (+0) bytes in 0 (+0) blocks
+     possibly lost: x (+x) bytes in 4 (+1) blocks
+   still reachable: x (-x) bytes in 3 (-1) blocks
+                      of which reachable via heuristic:
+                        length64           : 0 (-x) bytes in 0 (-1) blocks
+To see details of leaked memory, give 'full' arg to leak_check
+
+leak_check summary heuristics multipleinheritance,newarray,stdstring,length64
+LEAK SUMMARY:
+   definitely lost: x (+0) bytes in 1 (+0) blocks
+   indirectly lost: 0 (+0) bytes in 0 (+0) blocks
+     possibly lost: 0 (-x) bytes in 0 (-4) blocks
+   still reachable: x (+x) bytes in 7 (+4) blocks
+                      of which reachable via heuristic:
+                        length64           : x (+x) bytes in 1 (+1) blocks
+                        newarray           : x (+x) bytes in 1 (+1) blocks
+                        multipleinheritance: x (+x) bytes in 2 (+2) blocks
+To see details of leaked memory, give 'full' arg to leak_check
+
+leak_check summary heuristics all
+LEAK SUMMARY:
+   definitely lost: x (+0) bytes in 1 (+0) blocks
+   indirectly lost: 0 (+0) bytes in 0 (+0) blocks
+     possibly lost: 0 (+0) bytes in 0 (+0) blocks
+   still reachable: x (+0) bytes in 7 (+0) blocks
+                      of which reachable via heuristic:
+                        length64           : x (+0) bytes in 1 (+0) blocks
+                        newarray           : x (+0) bytes in 1 (+0) blocks
+                        multipleinheritance: x (+0) bytes in 2 (+0) blocks
+To see details of leaked memory, give 'full' arg to leak_check
+
+leak_check summary heuristics none
+LEAK SUMMARY:
+   definitely lost: x (+0) bytes in 1 (+0) blocks
+   indirectly lost: 0 (+0) bytes in 0 (+0) blocks
+     possibly lost: x (+x) bytes in 4 (+4) blocks
+   still reachable: x (-x) bytes in 3 (-4) blocks
+                      of which reachable via heuristic:
+                        length64           : 0 (-x) bytes in 0 (-1) blocks
+                        newarray           : 0 (-x) bytes in 0 (-1) blocks
+                        multipleinheritance: 0 (-x) bytes in 0 (-2) blocks
+To see details of leaked memory, give 'full' arg to leak_check
+
+Searching for pointers pointing in x bytes from 0x........
+*0x........ interior points at x bytes inside 0x........
+ Address 0x........ is 0 bytes inside data symbol "ptr"
+block at 0x........ considered reachable by ptr 0x........ using newarray heuristic
+Searching for pointers pointing in x bytes from 0x........
+*0x........ interior points at x 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
+destruct Ce
+destruct Be
+destruct Ae
+destruct Ce
+destruct Be
+destruct Ae
+destruct C
+destruct B
+destruct A
+destruct C
+destruct B
+destruct A
+Finished!
+
+HEAP SUMMARY:
+    in use at exit: 0 bytes in 0 blocks
+
+All heap blocks were freed -- no leaks are possible
+
+For lists of detected and suppressed errors, rerun with: -s
+ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)