Skip to content

Support for aligned_alloc#8

Open
ByteHamster wants to merge 1 commit intobingmann:masterfrom
ByteHamster-etc:aligned_alloc
Open

Support for aligned_alloc#8
ByteHamster wants to merge 1 commit intobingmann:masterfrom
ByteHamster-etc:aligned_alloc

Conversation

@ByteHamster
Copy link
Copy Markdown

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).

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).
@pdinklag
Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants