malloc_count
malloc_count copied to clipboard
Support for `aligned_alloc`
Without this change, calls to aligned_alloc are not counted.
Also, passing a pointer obtained from aligned_alloc to free
crashes the application (double free or corruption).
I'd like to confirm that this PR works.
However, this warning should definitely be fixed:
malloc_count/malloc_count.c:368:38: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
368 | extra_alignment = *(size_t*)(ptr + sizeof(size_t)) = 0;
Some background as to why this is important at all. We were trying to use malloc_count in the scope of AVX-512 computations and found that this simple program crashes:
#include <immintrin.h>
int main(int argc, char** argv) {
auto* array = new __m512i[100];
delete[] array;
return 0;
}
It crashes because for allocating the wide integer array, GCC uses aligned_alloc rather than malloc, but it uses free for the delete[] statement as usual.