diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h index 16146604b..a12990d24 100644 --- a/include/haproxy/pool.h +++ b/include/haproxy/pool.h @@ -101,6 +101,7 @@ extern int mem_poison_byte; /* set of POOL_DBG_* flags */ extern uint pool_debugging; +int is_trim_enabled(void); void *pool_get_from_os(struct pool_head *pool); void pool_put_to_os(struct pool_head *pool, void *ptr); void *pool_alloc_nocache(struct pool_head *pool); diff --git a/src/pattern.c b/src/pattern.c index a2557dea1..71f25a43b 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -2084,7 +2084,7 @@ int pat_ref_purge_range(struct pat_ref *ref, uint from, uint to, int budget) HA_RWLOCK_WRUNLOCK(PATEXP_LOCK, &expr->lock); #if defined(HA_HAVE_MALLOC_TRIM) - if (done) { + if (done && is_trim_enabled()) { malloc_trim(0); } #endif diff --git a/src/pool.c b/src/pool.c index 345681a0c..214d950fb 100644 --- a/src/pool.c +++ b/src/pool.c @@ -177,11 +177,10 @@ static void detect_allocator(void) my_mallctl = mallctl; #endif - - if (!my_mallctl) { + if (!my_mallctl) my_mallctl = get_sym_curr_addr("mallctl"); - using_default_allocator = (my_mallctl == NULL); - } + + using_default_allocator = (my_mallctl == NULL); if (!my_mallctl) { #if defined(HA_HAVE_MALLOC_TRIM) @@ -212,7 +211,7 @@ static void detect_allocator(void) } } -static int is_trim_enabled(void) +int is_trim_enabled(void) { return using_default_allocator; }