]> sourceware.org Git - valgrind.git/commitdiff
Fix a few issues with reallocf and add a FreeBSD amd64 regtest
authorPaul Floyd <pjfloyd@wanadoo.fr>
Fri, 17 Jun 2022 11:52:45 +0000 (13:52 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Fri, 17 Jun 2022 11:52:45 +0000 (13:52 +0200)
1. new_size is size_t (unsigned) and can't be negative
2. NULL not returned when the size is 0 and the memory freed
3. set ENOMEM if the allocation fails (but this time NULL does
   get returned)

.gitignore
coregrind/m_replacemalloc/vg_replace_malloc.c
memcheck/tests/amd64-freebsd/Makefile.am
memcheck/tests/amd64-freebsd/reallocf.c [new file with mode: 0644]
memcheck/tests/amd64-freebsd/reallocf.stderr.exp [new file with mode: 0644]
memcheck/tests/amd64-freebsd/reallocf.vgtest [new file with mode: 0644]

index 1bce8a62878ef2ac7a938d331c40d3f781968d24..8accdba2b7406aca8e28f64c4626db26f12535f5 100644 (file)
 /memcheck/tests/amd64-freebsd/Makefile.in
 /memcheck/tests/amd64-freebsd/posix_fadvise
 /memcheck/tests/amd64-freebsd/posix_fallocate
+/memcheck/tests/amd64-freebsd/reallocf
 
 # /memcheck/tests/x86-freebsd
 /memcheck/tests/x86-freebsd/*.stderr.diff
index 164c9ed910f84524c4c0d99efb26b1a98e2aa526..eb087676ca112f139c6c97e85d5a2fe50fbee34a 100644 (file)
@@ -1431,15 +1431,17 @@ extern int *___errno (void) __attribute__((weak));
             one which we know exists. */ \
          return VG_REPLACE_FUNCTION_EZU(10010,VG_Z_LIBC_SONAME,malloc) \
                    (new_size); \
-      if (new_size <= 0) { \
+      if (new_size == 0) { \
          VG_REPLACE_FUNCTION_EZU(10050,VG_Z_LIBC_SONAME,free)(ptrV); \
          MALLOC_TRACE(" = 0\n"); \
-         return NULL; \
+         return ptrV; \
       } \
       v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_realloc, ptrV, new_size ); \
       MALLOC_TRACE(" = %p\n", v ); \
-      if (v == NULL) \
+      if (v == NULL) {\
          VG_REPLACE_FUNCTION_EZU(10050,VG_Z_LIBC_SONAME,free)(ptrV); \
+         SET_ERRNO_ENOMEM; \
+      } \
       MALLOC_TRACE(" = %p\n", v ); \
       return v; \
    }
index 80854419dd47b19736249cea432332c57aa1d930..190fdd6aeb01378a533d6f204640ab0296ee3a65 100644 (file)
@@ -7,10 +7,12 @@ EXTRA_DIST = \
        posix_fadvise.vgtest \
        posix_fallocate.vgtest \
        posix_fadvise.stderr.exp \
-       posix_fallocate.stderr.exp
+       posix_fallocate.stderr.exp \
+       reallocf.vgtest \
+       reallocf.stderr.out
 
 check_PROGRAMS = \
-       posix_fadvise posix_fallocate
+       posix_fadvise posix_fallocate reallocf
 
 AM_CFLAGS    += @FLAG_M64@
 AM_CXXFLAGS  += @FLAG_M64@
diff --git a/memcheck/tests/amd64-freebsd/reallocf.c b/memcheck/tests/amd64-freebsd/reallocf.c
new file mode 100644 (file)
index 0000000..043d0d6
--- /dev/null
@@ -0,0 +1,22 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <errno.h>
+#include "../../memcheck.h"
+
+int main(void)
+{
+   int *pi = NULL;
+   VALGRIND_DO_LEAK_CHECK;
+   pi = reallocf(pi, 10*sizeof(int));
+   VALGRIND_DO_ADDED_LEAK_CHECK;
+   pi = reallocf(pi, 0);
+   VALGRIND_DO_CHANGED_LEAK_CHECK;
+   pi = NULL;
+   pi = realloc(pi, 10*sizeof(int));
+   VALGRIND_DO_ADDED_LEAK_CHECK;
+   errno = 0;
+   pi = reallocf(pi, 1UL << 49);
+   assert(!pi);
+   assert(errno == ENOMEM);
+   VALGRIND_DO_CHANGED_LEAK_CHECK;
+}
diff --git a/memcheck/tests/amd64-freebsd/reallocf.stderr.exp b/memcheck/tests/amd64-freebsd/reallocf.stderr.exp
new file mode 100644 (file)
index 0000000..b3e6658
--- /dev/null
@@ -0,0 +1,34 @@
+
+All heap blocks were freed -- no leaks are possible
+
+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 (+40) bytes in 1 (+1) 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
+
+All heap blocks were freed -- no leaks are possible
+
+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
+
+All heap blocks were freed -- no leaks are possible
+
+
+HEAP SUMMARY:
+    in use at exit: 0 bytes in 0 blocks
+  total heap usage: 3 allocs, 3 frees, 562,949,953,421,392 bytes allocated
+
+For a detailed leak analysis, rerun with: --leak-check=full
+
+For lists of detected and suppressed errors, rerun with: -s
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/memcheck/tests/amd64-freebsd/reallocf.vgtest b/memcheck/tests/amd64-freebsd/reallocf.vgtest
new file mode 100644 (file)
index 0000000..a01b083
--- /dev/null
@@ -0,0 +1 @@
+prog: reallocf
This page took 0.044355 seconds and 5 git commands to generate.