From ecd05ea13383e9aeba1932548b5303d0d2ff248f Mon Sep 17 00:00:00 2001 From: Fabrice Bellard Date: Tue, 2 Jun 2026 10:29:05 +0200 Subject: [PATCH] use the host malloc() for all allocations when ASAN is enabled --- quickjs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/quickjs.c b/quickjs.c index 750a304..0b39b4c 100644 --- a/quickjs.c +++ b/quickjs.c @@ -243,6 +243,12 @@ typedef enum OPCodeEnum OPCodeEnum; #define JS_MALLOC_BLOCK_SIZE_COUNT 31 #define JS_MALLOC_MIN_SMALL_SIZE 16 #define JS_MALLOC_MAX_SMALL_SIZE 512 +#if defined(__SANITIZE_ADDRESS__) +/* use the host malloc() for all allocations */ +#define JS_MALLOC_LARGE_BLOCKS_ONLY 1 +#else +#define JS_MALLOC_LARGE_BLOCKS_ONLY 0 +#endif /* allow iteration among the allocated blocks. Currently not used. May be used to suppress the memory overhead of JSGCObjectHeader */ @@ -1547,7 +1553,8 @@ static void *__js_malloc(JSMallocContext *s, size_t size) } else { total_size = ((size + JS_MALLOC_ALIGN - 1) & ~(JS_MALLOC_ALIGN - 1)) + sizeof(JSMallocBlockHeader); - if (total_size <= JS_MALLOC_MAX_SMALL_SIZE) { /* TEST */ + if (!JS_MALLOC_LARGE_BLOCKS_ONLY && + total_size <= JS_MALLOC_MAX_SMALL_SIZE) { int block_size_idx; unsigned int block_idx, block_size; JSMallocBlockHeader *b;