From: Josef 'Jeff' Sipek Date: Wed, 20 Jun 2018 16:24:34 +0000 (-0400) Subject: lib: mempool - Centralize p_free() NULL pointer check X-Git-Tag: 2.3.5~346 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=52954b8a236795685f8ce24536cbf633618ec11e;p=thirdparty%2Fdovecot%2Fcore.git 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. --- 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)