]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: [ip]_free(mem) is now also guaranteed to set mem=NULL
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 5 Oct 2016 11:18:07 +0000 (14:18 +0300)
committerGitLab <gitlab@git.dovecot.net>
Wed, 5 Oct 2016 21:13:36 +0000 (00:13 +0300)
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.

src/lib/imem.h
src/lib/mempool.h

index 4aaaa6e07ea663cb8e6f08a6bbbf1df53694d700..ef8b7f483fa657722a0ebcc95fcd23bf29bcd47e 100644 (file)
@@ -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;
index ae8bf6afc29fb827c0dea3990827e9ed7c1f1d04..e473496e13e64f15f555266802a9920f2987b758 100644 (file)
@@ -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)