Skip to content

Commit

Permalink
lib: mempool - Centralize p_free() NULL pointer check
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Josef 'Jeff' Sipek authored and sirainen committed Jul 4, 2018
1 parent 49c8a68 commit 7905a2c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/lib/mempool-allocfree.c
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/mempool.h
Expand Up @@ -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)
Expand Down

0 comments on commit 7905a2c

Please sign in to comment.