]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: mempool - Centralize p_free() NULL pointer check
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Wed, 20 Jun 2018 16:24:34 +0000 (12:24 -0400)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Wed, 6 Feb 2019 08:08:32 +0000 (10:08 +0200)
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
src/lib/mempool.h

index 4a53a91fae568f2e9c4dc18c339a9b2dc063038c..4b3d3b71f599e977664fca343f8f867150b359f7 100644 (file)
@@ -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);
index cd8db7ec9c6a3fe3da2eef3bb53b695d959ac997..7e43b20d46fb6b04faa58812951e85e66d768794 100644 (file)
@@ -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)