From: Timo Sirainen Date: Wed, 5 Oct 2016 11:18:07 +0000 (+0300) Subject: lib: [ip]_free(mem) is now also guaranteed to set mem=NULL X-Git-Tag: 2.3.0.rc1~2949 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cf4bdceafe382cda0f3b7ff39c5327fa96a00fba;p=thirdparty%2Fdovecot%2Fcore.git lib: [ip]_free(mem) is now also guaranteed to set mem=NULL It was already doing it, but updated the macros and comments to make it clear that this won't change in future. Changing this would only make it more likely that bugs occur and the performance improvements would be close to nonexistent. --- diff --git a/src/lib/imem.h b/src/lib/imem.h index 4aaaa6e07e..ef8b7f483f 100644 --- a/src/lib/imem.h +++ b/src/lib/imem.h @@ -11,8 +11,10 @@ void *i_malloc(size_t size) ATTR_MALLOC ATTR_RETURNS_NONNULL; void *i_realloc(void *mem, size_t old_size, size_t new_size) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL; -#define i_free(mem) p_free(default_pool, mem) -#define i_free_and_null(mem) p_free_and_null(default_pool, mem) +/* i_free() and i_free_and_null() are now guaranteed to both set mem=NULL, + so either one of them can be used. */ +#define i_free(mem) p_free_and_null(default_pool, mem) +#define i_free_and_null(mem) i_free(mem) /* string functions */ char *i_strdup(const char *str) ATTR_MALLOC; diff --git a/src/lib/mempool.h b/src/lib/mempool.h index ae8bf6afc2..e473496e13 100644 --- a/src/lib/mempool.h +++ b/src/lib/mempool.h @@ -82,17 +82,13 @@ p_realloc(pool_t pool, void *mem, size_t old_size, size_t new_size) return pool->v->realloc(pool, mem, old_size, new_size); } -/* Free the memory. Currently it also sets memory to NULL, but that shouldn't - be relied on as it's only an extra safety check. It might as well be later - changed to some invalid pointer causing a segfault, or removed completely - in some "optimization".. */ +/* Free the memory. p_free() and p_free_and_null() are now guaranteed to both + set mem=NULL, so either one of them can be used. */ #define p_free(pool, mem) \ STMT_START { \ p_free_internal(pool, mem); \ (mem) = NULL; \ } STMT_END - -/* A macro that's guaranteed to set mem = NULL. */ #define p_free_and_null(pool, mem) p_free(pool, mem) static inline void p_free_internal(pool_t pool, void *mem)