From f13322ede1e4824e20fb871dabd22e91dcc8ab0a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 22 Nov 2017 10:50:54 +0100 Subject: [PATCH] MINOR: pools: prepare functions to override malloc/free in pools This will be useful to add some debugging capabilities. For now it changes nothing. --- include/common/memory.h | 17 +++++++++++++++++ src/memory.c | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/common/memory.h b/include/common/memory.h index a5c0ec49ef..9277ab6f41 100644 --- a/include/common/memory.h +++ b/include/common/memory.h @@ -155,6 +155,23 @@ static inline void *pool_alloc_dirty(struct pool_head *pool) return p; } +/* allocates an area of size and returns it. The semantics are similar + * to those of malloc(). + */ +static inline void *pool_alloc_area(size_t size) +{ + return malloc(size); +} + +/* frees an area of size allocated by pool_alloc_area(). The + * semantics are identical to free() except that the size is specified and + * may be ignored. + */ +static inline void pool_free_area(void *area, size_t __maybe_unused size) +{ + free(area); +} + /* * Returns a pointer to type taken from the pool or * dynamically allocated. In the first case, is updated to point to diff --git a/src/memory.c b/src/memory.c index b0b32e7a74..fc1f62483d 100644 --- a/src/memory.c +++ b/src/memory.c @@ -117,7 +117,7 @@ void *__pool_refill_alloc(struct pool_head *pool, unsigned int avail) if (pool->limit && pool->allocated >= pool->limit) return NULL; - ptr = malloc(pool->size + POOL_EXTRA); + ptr = pool_alloc_area(pool->size + POOL_EXTRA); if (!ptr) { pool->failed++; if (failed) @@ -163,7 +163,7 @@ void pool_flush2(struct pool_head *pool) temp = next; next = *POOL_LINK(pool, temp); pool->allocated--; - free(temp); + pool_free_area(temp, pool->size + POOL_EXTRA); } pool->free_list = next; HA_SPIN_UNLOCK(POOL_LOCK, &pool->lock); @@ -199,7 +199,7 @@ void pool_gc2(struct pool_head *pool_ctx) temp = next; next = *POOL_LINK(entry, temp); entry->allocated--; - free(temp); + pool_free_area(temp, entry->size + POOL_EXTRA); } entry->free_list = next; if (entry != pool_ctx)