The simple program
causes valgrind(1) to complain about a spurious invalid free():
==1557== Memcheck, a memory error detector
==1557== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==1557== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==1557== Command: ./a
==1557== Invalid free() / delete / delete / realloc()
==1557== at 0x4C232BC: free (in /usr/local/lib/valgrind/vgpreload_memcheck-amd64-freebsd.so)
==1557== by 0x4007CB: main (in /tmp/a)
==1557== Address 0x5806058 is not stack'd, malloc'd or (recently) free'd
==1557== HEAP SUMMARY:
==1557== in use at exit: 0 bytes in 0 blocks
==1557== total heap usage: 0 allocs, 1 frees, 0 bytes allocated
==1557== All heap blocks were freed -- no leaks are possible
==1557== For counts of detected and suppressed errors, rerun with: -v
==1557== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
I suspect that valgrind doesn't properly intercept aligned_alloc(3) and thus doesn't
recognize the address when it is passed to free(). This issue does not occur on Linux,
I suspect it comes from the interaction between jemalloc(3) and valgrind.
see also Bug #220943.
Maintainership dropped ports r495096.
Assign to new maintainer.
This feature is not yet supported in mainline Valgrind. See
I'll look into adding a patch for this.
I created a patch (see the kde.org bugzilla item), but it doesn't work well on Linux because aligned_alloc and memalign alias the same function in libc. I'll check on FreeBSD.
On FreeBSD I get the output below, so this would be a worthwhile change.
==9965== Memcheck, a memory error detector
==9965== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==9965== Using Valgrind-3.16.0.GIT and LibVEX; rerun with -h for copyright info
==9965== Command: ./aligned_alloc
default-aligned addr: 0x5800040
1024-byte aligned addr: 0x5801400
==9965== HEAP SUMMARY:
==9965== in use at exit: 4,096 bytes in 1 blocks
==9965== total heap usage: 3 allocs, 2 frees, 8,232 bytes allocated
==9965== LEAK SUMMARY:
==9965== definitely lost: 0 bytes in 0 blocks
==9965== indirectly lost: 0 bytes in 0 blocks
==9965== possibly lost: 0 bytes in 0 blocks
==9965== still reachable: 4,096 bytes in 1 blocks
==9965== suppressed: 0 bytes in 0 blocks
==9965== Rerun with --leak-check=full to see details of leaked memory
==9965== For lists of detected and suppressed errors, rerun with: -s
==9965== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
This should now be fixed in devel/valgrind-devel and this item can be closed.
Can confirm, this problem no-longer exists in current valgrind-devel.
Thanks a lot for the work!