mimalloc icon indicating copy to clipboard operation
mimalloc copied to clipboard

Wrong mimalloc stat with asan

Open thweetkomputer opened this issue 1 year ago • 1 comments

#include <stdlib.h>

int main() {
    int *a = (int *)malloc(sizeof(int));
    *a = 1;
    
    return 0;
}

Hi, I wrote a demo and want to use mimalloc with asan enabled.

 gcc test.c -I/usr/local/include/mimalloc-2.1 -lmimalloc-asan-debug -fsanitize=address -fsanitize-recover=address -lpthre

I found that the stats all become zero, is this normal? image

But the stat shows normally when asan is disabled. image

Can you help me?

thweetkomputer avatar Sep 11 '24 07:09 thweetkomputer

If you just need ASan’s checks and mimalloc for the allocation, try using ASan with mimalloc without enabling mimalloc’s stats:

gcc test.c -I/usr/local/include/mimalloc-2.1 -lmimalloc-asan-debug -fsanitize=address -fsanitize-recover=address -lpthread 

If you need mimalloc stats, disable ASan for the time being or use mimalloc’s default allocator without ASan’s intervention. You could compile with:

gcc test.c -I/usr/local/include/mimalloc-2.1 -lmimalloc -lm -lpthread

This should ensure that mimalloc tracks memory correctly and reports statistics.

imsharukh1994 avatar Dec 25 '24 09:12 imsharukh1994