With Fedora 44 these are now generally available.
/memcheck/tests/bug464969_d_demangle
/memcheck/tests/bug472219
/memcheck/tests/bug484002
+/memcheck/tests/c23_free
/memcheck/tests/calloc-overflow
/memcheck/tests/cdebug_zlib
/memcheck/tests/cdebug_zlib_gnu
strndup \
close_range \
wcsncpy \
+ free_sized \
free_aligned_sized \
sbrk \
wcpncpy \
[test x$ac_cv_func_strlcat = xyes])
AM_CONDITIONAL([HAVE_STRLCPY],
[test x$ac_cv_func_strlcpy = xyes])
+AM_CONDITIONAL([HAVE_FREE_SIZED],
+ [test x$ac_cv_func_free_sized = xyes])
AM_CONDITIONAL([HAVE_FREE_ALIGNED_SIZED],
[test x$ac_cv_func_free_aligned_sized = xyes])
AM_CONDITIONAL([HAVE_SBRK],
bug464969_d_demangle.stdout.exp \
bug472219.vgtest \
bug484002.stdout.exp bug484002.vgtest \
+ c23_free.stderr.exp c23_free.vgtest \
calloc-overflow.stderr.exp calloc-overflow.vgtest\
cdebug_zstd.vgtest cdebug_zstd.stderr.exp \
cdebug_zlib.stderr.exp cdebug_zlib.vgtest \
check_PROGRAMS += bug484002
endif
+if HAVE_FREE_SIZED
+if HAVE_FREE_ALIGNED_SIZED
+check_PROGRAMS += c23_free
+c23_free_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_UNINITIALIZED@
+endif
+endif
+
if GZ_ZLIB
check_PROGRAMS += cdebug_zlib
cdebug_zlib_SOURCES = cdebug.c
--- /dev/null
+#include "stdlib.h"
+
+int main(void)
+{
+ char* a = aligned_alloc(256, 1024);
+ char* b = aligned_alloc(256, 1024);
+ free_sized(a, 1024);
+ free_aligned_sized(b, 256, 1024);
+
+ a = malloc(1000);
+ free_sized(a, 1000);
+
+ a = calloc(999, sizeof(*a));
+ free_sized(a, 999);
+
+ a = malloc(1001);
+ a = realloc(a, 2001);
+ free_sized(a, 2001);
+
+ a = aligned_alloc(1, 256);
+ free_aligned_sized(a, 1, 256);
+
+ // some errors
+ a = malloc(1000);
+ // mismatch size, larger
+ free_sized(a, 1024);
+ a = malloc(1000);
+ // mismatch size, smaller
+ free_sized(a, 990);
+
+ size_t s = 1024;
+ size_t u;
+ // make s uninitialised but keep value of 1024
+ s += u;
+ s -= u;
+ a = aligned_alloc(256, 1024);
+ // uninit size
+ free_sized(a, s);
+
+ a = malloc(1000);
+ // align not power of 2
+ free_aligned_sized(a, 1000, 1000);
+
+ a = aligned_alloc(256, 4096);
+ // align mismatch
+ free_aligned_sized(a, 128, 4096);
+
+ a = aligned_alloc(256, 2048);
+ // size mismatch
+ free_aligned_sized(a, 256, 1024);
+
+ a = aligned_alloc(256, 1024);
+ // uninit size
+ free_aligned_sized(a, 256, s);
+
+ a = aligned_alloc(1024, 1024);
+ // uninit alignment
+ free_aligned_sized(a, s, 1024);
+
+ // NULL pointers
+ free_sized(NULL, 32);
+ free_aligned_sized(NULL, 32, 128);
+}
--- /dev/null
+Mismatched aligned_alloc/free_sized size value: 1024
+ at 0x........: free_sized (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:26)
+ Address 0x........ is 0 bytes inside a block of size 1,000 alloc'd
+ at 0x........: malloc (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:24)
+
+Mismatched aligned_alloc/free_sized size value: 990
+ at 0x........: free_sized (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:29)
+ Address 0x........ is 0 bytes inside a block of size 1,000 alloc'd
+ at 0x........: malloc (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:27)
+
+Conditional jump or move depends on uninitialised value(s)
+ at 0x........: free_sized (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:38)
+
+Invalid alignment value: 1000 (should be a power of 2)
+ at 0x........: free_aligned_sized (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:42)
+
+Mismatched aligned_alloc/free_aligned_sized alignment alloc value: 0 dealloc value: 1000
+ at 0x........: free_aligned_sized (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:42)
+ Address 0x........ is 0 bytes inside a block of size 1,000 alloc'd
+ at 0x........: malloc (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:40)
+
+Mismatched aligned_alloc/free_aligned_sized alignment alloc value: 256 dealloc value: 128
+ at 0x........: free_aligned_sized (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:46)
+ Address 0x........ is 0 bytes inside a block of size 4,096 alloc'd
+ at 0x........: aligned_alloc (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:44)
+
+Mismatched aligned_alloc/free_aligned_sized size value: 1024
+ at 0x........: free_aligned_sized (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:50)
+ Address 0x........ is 0 bytes inside a block of size 2,048 alloc'd
+ at 0x........: aligned_alloc (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:48)
+
+Conditional jump or move depends on uninitialised value(s)
+ at 0x........: free_aligned_sized (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:54)
+
+Conditional jump or move depends on uninitialised value(s)
+ at 0x........: free_aligned_sized (vg_replace_malloc.c:...)
+ by 0x........: main (c23_free.c:58)
+
--- /dev/null
+prereq: test -e ./c23_free
+prog: c23_free
+vgopts: -q