From: Willy Tarreau Date: Sun, 28 Oct 2018 19:09:12 +0000 (+0100) Subject: BUG/MINOR: memory: make the thread-local cache allocator set the debugging link X-Git-Tag: v1.9-dev5~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8e9f4531cb18d424139285557f0fe0895fd46c5b;p=thirdparty%2Fhaproxy.git BUG/MINOR: memory: make the thread-local cache allocator set the debugging link When building with DEBUG_MEMORY_POOLS, an element returned from the cache would not have its pool link initialized unless it's allocated using pool_alloc(). This is problematic for buffer allocators which use pool_alloc_dirty(), as freeing this object will make the code think it was allocated from another pool. This patch does two things : - make __pool_get_from_cache() set the link - remove the extra initialization from pool_alloc() since it's always done in either __pool_get_first() or __pool_refill_alloc() This patch is marked MINOR since it only affects code explicitly built for debugging. No backport is needed. --- diff --git a/include/common/memory.h b/include/common/memory.h index 2301e3ad53..b854ebb0b2 100644 --- a/include/common/memory.h +++ b/include/common/memory.h @@ -180,6 +180,10 @@ static inline void *__pool_get_from_cache(struct pool_head *pool) pool_cache_count--; LIST_DEL(&item->by_pool); LIST_DEL(&item->by_lru); +#ifdef DEBUG_MEMORY_POOLS + /* keep track of where the element was allocated from */ + *POOL_LINK(pool, item) = (void *)pool; +#endif return item; } @@ -248,12 +252,6 @@ static inline void *pool_alloc(struct pool_head *pool) void *p; p = pool_alloc_dirty(pool); -#ifdef DEBUG_MEMORY_POOLS - if (p) { - /* keep track of where the element was allocated from */ - *POOL_LINK(pool, p) = (void *)pool; - } -#endif if (p && mem_poison_byte >= 0) { memset(p, mem_poison_byte, pool->size); } @@ -436,14 +434,6 @@ static inline void *pool_alloc(struct pool_head *pool) void *p; p = pool_alloc_dirty(pool); -#ifdef DEBUG_MEMORY_POOLS - if (p) { - HA_SPIN_LOCK(POOL_LOCK, &pool->lock); - /* keep track of where the element was allocated from */ - *POOL_LINK(pool, p) = (void *)pool; - HA_SPIN_UNLOCK(POOL_LOCK, &pool->lock); - } -#endif if (p && mem_poison_byte >= 0) { memset(p, mem_poison_byte, pool->size); }