From 7905a2cf06e680c021c46f753530356d81c7bf18 Mon Sep 17 00:00:00 2001 From: Josef 'Jeff' Sipek Date: Wed, 20 Jun 2018 12:24:34 -0400 Subject: [PATCH] lib: mempool - Centralize p_free() NULL pointer check This changes the behavior of p_free(pool, some_null_pointer) slightly. datastack mempools: Previously, the datastack frame id was checked regardless of whether or not the pointer was NULL. Now, only non-NULL pointers perform this check. system mempools: Previously, the process would SIGSEGV if a NULL pointer was freed in a debug binary on a system with malloc_usable_size(). Now, no SIGSEGV occurs. allocfree, alloconly, and unsafe datastack: No change in behavior. --- src/lib/mempool-allocfree.c | 2 -- src/lib/mempool.h | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/mempool-allocfree.c b/src/lib/mempool-allocfree.c index 4a53a91fae..4b3d3b71f5 100644 --- a/src/lib/mempool-allocfree.c +++ b/src/lib/mempool-allocfree.c @@ -267,8 +267,6 @@ static void pool_allocfree_free(pool_t pool, void *mem) { struct allocfree_pool *apool = container_of(pool, struct allocfree_pool, pool); - if (mem == NULL) - return; struct pool_block *block = pool_block_detach(apool, mem); if (apool->clean_frees) safe_memset(block, 0, SIZEOF_POOLBLOCK+block->size); diff --git a/src/lib/mempool.h b/src/lib/mempool.h index cd8db7ec9c..7e43b20d46 100644 --- a/src/lib/mempool.h +++ b/src/lib/mempool.h @@ -130,7 +130,8 @@ p_realloc(pool_t pool, void *mem, size_t old_size, size_t new_size) static inline void p_free_internal(pool_t pool, void *mem) { - pool->v->free(pool, mem); + if (mem != NULL) + pool->v->free(pool, mem); } static inline void p_clear(pool_t pool)