]> git.kaiwu.me - quickjs.git/commitdiff
use the host malloc() for all allocations when ASAN is enabled
authorFabrice Bellard <fabrice@bellard.org>
Tue, 2 Jun 2026 08:29:05 +0000 (10:29 +0200)
committerFabrice Bellard <fabrice@bellard.org>
Tue, 2 Jun 2026 08:43:18 +0000 (10:43 +0200)
quickjs.c

index 750a3043fa7086546e84d67ca3c85e52e3770a4e..0b39b4c7708ce4e8e92fabd42b8ec108dfbe9e36 100644 (file)
--- 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;