]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Linux reallocarray: update testcase and expected master
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 8 Feb 2026 18:09:25 +0000 (19:09 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 8 Feb 2026 18:09:25 +0000 (19:09 +0100)
memcheck/tests/amd64-freebsd/reallocarray.c
memcheck/tests/amd64-linux/reallocarray.c
memcheck/tests/amd64-linux/reallocarray.stderr.exp

index 24ed47072cc8f3b7b8f6cec51dc0988f48025bdc..5735383a3f1dfa7e77aa6ed3be802badeaef1d4a 100644 (file)
@@ -31,7 +31,7 @@ int main(void)
    fprintf(stderr, "Added leak check, expect 40 bytes still reachable\n");
    VALGRIND_DO_ADDED_LEAK_CHECK;
    errno = 0;
-   /* this will fail in the mallloc lib, not enough memory */
+   /* this will fail in the malloc lib, not enough memory */
    newpi = reallocarray(pi, 1UL << 49, 1U);
    assert(!newpi);
    assert(errno == ENOMEM);
index ce63b80100da41b446a00c3d43f13ff4e48d6967..138f1da06926e5b20285a11de161eda626492463 100644 (file)
@@ -8,24 +8,41 @@
 int main(void)
 {
    int *pi = NULL;
+   int *newpi;
    VALGRIND_DO_LEAK_CHECK;
+   /* should succeed */
    pi = reallocarray(pi, 10U, sizeof(int));
+   assert(pi);
+   fprintf(stderr, "Added leak check, expect 40 bytes still reachable\n");
    VALGRIND_DO_ADDED_LEAK_CHECK;
+   /* on Linux this does free pi */
    pi = reallocarray(pi, 0U, sizeof(int));
+   assert(!pi);
+   fprintf(stderr, "Added leak check, expect all blocks freed\n");
    VALGRIND_DO_ADDED_LEAK_CHECK;
    pi = malloc(10U);
+   assert(pi);
    pi = reallocarray(pi, 10U, 0U);
+   assert(!pi);
+   fprintf(stderr, "Added leak check, expect all blocks freed\n");
    VALGRIND_DO_CHANGED_LEAK_CHECK;
    pi = NULL;
    pi = reallocarray(pi, 10U, sizeof(int));
+   assert(pi);
+   fprintf(stderr, "Added leak check, expect 40 bytes still reachable\n");
    VALGRIND_DO_ADDED_LEAK_CHECK;
    errno = 0;
-   pi = reallocarray(pi, 1UL << 49, 1U);
-   assert(!pi);
+   /* this will fail in the malloc lib, not enough memory */
+   newpi = reallocarray(pi, 1UL << 49, 1U);
+   assert(!newpi);
    assert(errno == ENOMEM);
+   fprintf(stderr, "Added leak check, expect 40 bytes still reachable\n");
    VALGRIND_DO_CHANGED_LEAK_CHECK;
-   pi = reallocarray(pi, SIZE_MAX/1000U, SIZE_MAX/1000U);
-   assert(!pi);
+   /* this will fail the reallocarray precondition */
+   newpi = reallocarray(pi, SIZE_MAX/1000U, SIZE_MAX/1000U);
+   assert(!newpi);
    assert(errno == ENOMEM);
+   free(pi);
+   fprintf(stderr, "Added leak check, expect all blocks freed\n");
    VALGRIND_DO_CHANGED_LEAK_CHECK;
 }
index 20a1c4e8b4f962c16ed928afd3d113495b563829..934c095bee0f5740df462a3ff7a5f225dd7fe0b1 100644 (file)
@@ -1,6 +1,7 @@
 
 All heap blocks were freed -- no leaks are possible
 
+Added leak check, expect 40 bytes still reachable
 LEAK SUMMARY:
    definitely lost: 0 (+0) bytes in 0 (+0) blocks
    indirectly lost: 0 (+0) bytes in 0 (+0) blocks
@@ -12,22 +13,25 @@ To see them, rerun with: --leak-check=full --show-leak-kinds=all
 
 realloc() with size 0
    at 0x........: reallocarray (vg_replace_malloc.c:...)
-   by 0x........: main (reallocarray.c:14)
+   by 0x........: main (reallocarray.c:19)
  Address 0x........ is 0 bytes inside a block of size 40 alloc'd
    at 0x........: reallocarray (vg_replace_malloc.c:...)
-   by 0x........: main (reallocarray.c:12)
+   by 0x........: main (reallocarray.c:14)
 
+Added leak check, expect all blocks freed
 All heap blocks were freed -- no leaks are possible
 
 realloc() with size 0
    at 0x........: reallocarray (vg_replace_malloc.c:...)
-   by 0x........: main (reallocarray.c:17)
+   by 0x........: main (reallocarray.c:25)
  Address 0x........ is 0 bytes inside a block of size 10 alloc'd
    at 0x........: malloc (vg_replace_malloc.c:...)
-   by 0x........: main (reallocarray.c:16)
+   by 0x........: main (reallocarray.c:23)
 
+Added leak check, expect all blocks freed
 All heap blocks were freed -- no leaks are possible
 
+Added leak check, expect 40 bytes still reachable
 LEAK SUMMARY:
    definitely lost: 0 (+0) bytes in 0 (+0) blocks
    indirectly lost: 0 (+0) bytes in 0 (+0) blocks
@@ -37,8 +41,17 @@ LEAK SUMMARY:
 Reachable blocks (those to which a pointer was found) are not shown.
 To see them, rerun with: --leak-check=full --show-leak-kinds=all
 
-All heap blocks were freed -- no leaks are possible
+Added leak check, expect 40 bytes still reachable
+LEAK SUMMARY:
+   definitely lost: 0 (+0) bytes in 0 (+0) blocks
+   indirectly lost: 0 (+0) bytes in 0 (+0) blocks
+     possibly lost: 0 (+0) bytes in 0 (+0) blocks
+   still reachable: 40 (+0) bytes in 1 (+0) blocks
+        suppressed: 0 (+0) bytes in 0 (+0) 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
 
+Added leak check, expect all blocks freed
 All heap blocks were freed -- no leaks are possible