From 2e96bc9ee46ae0ebbb0640cdacfe57813b519d54 Mon Sep 17 00:00:00 2001 From: Joshua Root Date: Tue, 5 Mar 2024 01:12:06 +1100 Subject: [PATCH 1/3] Fix min macOS for pressure_relief This field exists in the 10.7 and later SDKs. --- src/prim/osx/alloc-override-zone.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/prim/osx/alloc-override-zone.c b/src/prim/osx/alloc-override-zone.c index 0e0a99d9..9a317750 100644 --- a/src/prim/osx/alloc-override-zone.c +++ b/src/prim/osx/alloc-override-zone.c @@ -225,7 +225,9 @@ static malloc_zone_t mi_malloc_zone = { // switch to version 9+ on OSX 10.6 to support memalign. .memalign = &zone_memalign, .free_definite_size = &zone_free_definite_size, + #if defined(MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) .pressure_relief = &zone_pressure_relief, + #endif #if defined(MAC_OS_X_VERSION_10_14) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14) .claimed_address = &zone_claimed_address, #endif From f508ae552888d988cc828e70634061867e3a477b Mon Sep 17 00:00:00 2001 From: Joshua Root Date: Tue, 5 Mar 2024 01:28:10 +1100 Subject: [PATCH 2/3] Only interpose strndup if it exists Added in the macOS 10.7 SDK. --- src/alloc-override.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/alloc-override.c b/src/alloc-override.c index 7cf0bf2c..b2c94ce2 100644 --- a/src/alloc-override.c +++ b/src/alloc-override.c @@ -77,7 +77,9 @@ typedef struct mi_nothrow_s { int _tag; } mi_nothrow_t; MI_INTERPOSE_MI(calloc), MI_INTERPOSE_MI(realloc), MI_INTERPOSE_MI(strdup), + #if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 MI_INTERPOSE_MI(strndup), + #endif MI_INTERPOSE_MI(realpath), MI_INTERPOSE_MI(posix_memalign), MI_INTERPOSE_MI(reallocf), From bb1fafa1bbea44e0421256b9c99dfdf67452873a Mon Sep 17 00:00:00 2001 From: Daan Date: Fri, 19 Apr 2024 10:34:04 -0700 Subject: [PATCH 3/3] forward strdup/strndup to avoid leaks on macOS -- addresses PR #769 --- src/alloc-override.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/alloc-override.c b/src/alloc-override.c index b2c94ce2..92536976 100644 --- a/src/alloc-override.c +++ b/src/alloc-override.c @@ -130,11 +130,16 @@ typedef struct mi_nothrow_s { int _tag; } mi_nothrow_t; // cannot override malloc unless using a dll. // we just override new/delete which does work in a static library. #else - // On all other systems forward to our API + // On all other systems forward allocation primitives to our API mi_decl_export void* malloc(size_t size) MI_FORWARD1(mi_malloc, size) mi_decl_export void* calloc(size_t size, size_t n) MI_FORWARD2(mi_calloc, size, n) mi_decl_export void* realloc(void* p, size_t newsize) MI_FORWARD2(mi_realloc, p, newsize) - mi_decl_export void free(void* p) MI_FORWARD0(mi_free, p) + mi_decl_export void free(void* p) MI_FORWARD0(mi_free, p) + // In principle we do not need to forward `strdup`/`strndup` but on some systems these do not use `malloc` internally (but a more primitive call) + mi_decl_export char* strdup(const char* str) MI_FORWARD1(mi_strdup, str) + #if !defined(__APPLE__) || (defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) + mi_decl_export char* strndup(const char* str, size_t n) MI_FORWARD2(mi_strndup, str, n) + #endif #endif #if (defined(__GNUC__) || defined(__clang__)) && !defined(__APPLE__)