Mercurial > dovecot > core-2.2
changeset 3878:bf0a03691989 HEAD
pool_unref(): set the pool pointer to NULL, so if we're trying to unref it
twice we'll do a clean crash.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 14 Jan 2006 19:23:22 +0200 |
parents | 0d0fad3fb5e9 |
children | 928229f8b3e6 |
files | src/lib/mempool-alloconly.c src/lib/mempool-datastack.c src/lib/mempool-system.c src/lib/mempool-unsafe-datastack.c src/lib/mempool.h |
diffstat | 5 files changed, 18 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/mempool-alloconly.c Sat Jan 14 19:14:28 2006 +0200 +++ b/src/lib/mempool-alloconly.c Sat Jan 14 19:23:22 2006 +0200 @@ -41,7 +41,7 @@ static const char *pool_alloconly_get_name(pool_t pool); static void pool_alloconly_ref(pool_t pool); -static void pool_alloconly_unref(pool_t pool); +static void pool_alloconly_unref(pool_t *pool); static void *pool_alloconly_malloc(pool_t pool, size_t size); static void pool_alloconly_free(pool_t pool, void *mem); static void *pool_alloconly_realloc(pool_t pool, void *mem, @@ -137,9 +137,13 @@ apool->refcount++; } -static void pool_alloconly_unref(pool_t pool) +static void pool_alloconly_unref(pool_t *pool) { - struct alloconly_pool *apool = (struct alloconly_pool *) pool; + struct alloconly_pool *apool = (struct alloconly_pool *)*pool; + + /* erase the pointer before freeing anything, as the pointer may + exist inside the pool's memory area */ + *pool = NULL; if (--apool->refcount == 0) pool_alloconly_destroy(apool);
--- a/src/lib/mempool-datastack.c Sat Jan 14 19:14:28 2006 +0200 +++ b/src/lib/mempool-datastack.c Sat Jan 14 19:23:22 2006 +0200 @@ -7,7 +7,7 @@ static const char *pool_data_stack_get_name(pool_t pool); static void pool_data_stack_ref(pool_t pool); -static void pool_data_stack_unref(pool_t pool); +static void pool_data_stack_unref(pool_t *pool); static void *pool_data_stack_malloc(pool_t pool, size_t size); static void pool_data_stack_free(pool_t pool, void *mem); static void *pool_data_stack_realloc(pool_t pool, void *mem, @@ -66,15 +66,17 @@ dpool->refcount++; } -static void pool_data_stack_unref(pool_t pool) +static void pool_data_stack_unref(pool_t *pool) { - struct datastack_pool *dpool = (struct datastack_pool *) pool; + struct datastack_pool *dpool = (struct datastack_pool *)*pool; if (dpool->data_stack_frame != data_stack_frame) i_panic("pool_data_stack_unref(): stack frame changed"); dpool->refcount--; i_assert(dpool->refcount >= 0); + + *pool = NULL; } static void *pool_data_stack_malloc(pool_t pool __attr_unused__, size_t size)
--- a/src/lib/mempool-system.c Sat Jan 14 19:14:28 2006 +0200 +++ b/src/lib/mempool-system.c Sat Jan 14 19:23:22 2006 +0200 @@ -15,7 +15,7 @@ static const char *pool_system_get_name(pool_t pool); static void pool_system_ref(pool_t pool); -static void pool_system_unref(pool_t pool); +static void pool_system_unref(pool_t *pool); static void *pool_system_malloc(pool_t pool, size_t size); static void pool_system_free(pool_t pool, void *mem); static void *pool_system_realloc(pool_t pool, void *mem, @@ -52,7 +52,7 @@ { } -static void pool_system_unref(pool_t pool __attr_unused__) +static void pool_system_unref(pool_t *pool __attr_unused__) { }
--- a/src/lib/mempool-unsafe-datastack.c Sat Jan 14 19:14:28 2006 +0200 +++ b/src/lib/mempool-unsafe-datastack.c Sat Jan 14 19:23:22 2006 +0200 @@ -7,7 +7,7 @@ static const char *pool_unsafe_data_stack_get_name(pool_t pool); static void pool_unsafe_data_stack_ref(pool_t pool); -static void pool_unsafe_data_stack_unref(pool_t pool); +static void pool_unsafe_data_stack_unref(pool_t *pool); static void *pool_unsafe_data_stack_malloc(pool_t pool, size_t size); static void pool_unsafe_data_stack_free(pool_t pool, void *mem); static void *pool_unsafe_data_stack_realloc(pool_t pool, void *mem, @@ -44,7 +44,7 @@ { } -static void pool_unsafe_data_stack_unref(pool_t pool __attr_unused__) +static void pool_unsafe_data_stack_unref(pool_t *pool __attr_unused__) { }
--- a/src/lib/mempool.h Sat Jan 14 19:14:28 2006 +0200 +++ b/src/lib/mempool.h Sat Jan 14 19:23:22 2006 +0200 @@ -13,7 +13,7 @@ const char *(*get_name)(pool_t pool); void (*ref)(pool_t pool); - void (*unref)(pool_t pool); + void (*unref)(pool_t *pool); void *(*malloc)(pool_t pool, size_t size); void (*free)(pool_t pool, void *mem); @@ -58,7 +58,7 @@ /* Pools should be used through these macros: */ #define pool_get_name(pool) (pool)->get_name(pool) #define pool_ref(pool) (pool)->ref(pool) -#define pool_unref(pool) (pool)->unref(pool) +#define pool_unref(pool) (pool)->unref(&(pool)) #define p_new(pool, type, count) \ ((type *) p_malloc(pool, sizeof(type) * (count)))