mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 15:17:01 +02:00
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.
This commit is contained in:
parent
f95838ca2d
commit
8e9f4531cb
@ -180,6 +180,10 @@ static inline void *__pool_get_from_cache(struct pool_head *pool)
|
|||||||
pool_cache_count--;
|
pool_cache_count--;
|
||||||
LIST_DEL(&item->by_pool);
|
LIST_DEL(&item->by_pool);
|
||||||
LIST_DEL(&item->by_lru);
|
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;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,12 +252,6 @@ static inline void *pool_alloc(struct pool_head *pool)
|
|||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
p = pool_alloc_dirty(pool);
|
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) {
|
if (p && mem_poison_byte >= 0) {
|
||||||
memset(p, mem_poison_byte, pool->size);
|
memset(p, mem_poison_byte, pool->size);
|
||||||
}
|
}
|
||||||
@ -436,14 +434,6 @@ static inline void *pool_alloc(struct pool_head *pool)
|
|||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
p = pool_alloc_dirty(pool);
|
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) {
|
if (p && mem_poison_byte >= 0) {
|
||||||
memset(p, mem_poison_byte, pool->size);
|
memset(p, mem_poison_byte, pool->size);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user