]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Make i_free(), p_free() and pool_unref() calls also set the given parameter
authorTimo Sirainen <tss@iki.fi>
Sun, 21 Sep 2003 16:39:29 +0000 (19:39 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 21 Sep 2003 16:39:29 +0000 (19:39 +0300)
to NULL.

--HG--
branch : HEAD

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

index bda3c6dbf494e11735bc1f150f8c988832bf3dfc..05412e7bb91a993ad00d793391732e03b0b9b429 100644 (file)
@@ -9,11 +9,6 @@ void *i_malloc(size_t size)
         return p_malloc(default_pool, size);
 }
 
-void i_free(void *mem)
-{
-        p_free(default_pool, mem);
-}
-
 void *i_realloc(void *mem, size_t old_size, size_t new_size)
 {
         return p_realloc(default_pool, mem, old_size, new_size);
index 1ef688733626f9f75117ad3c056fdabe3ed3935e..fc70c915b99b9c5c2df997aee637d3f9eb1dbb39 100644 (file)
@@ -6,10 +6,16 @@ extern pool_t default_pool;
 /* For easy allocation of memory from default memory pool. */
 #define i_new(type, count) \
         ((type *) i_malloc(sizeof(type) * (count)))
+
 void *i_malloc(size_t size);
-void i_free(void *mem);
 void *i_realloc(void *mem, size_t old_size, size_t new_size);
 
+#define i_free(mem) \
+       STMT_START { \
+          p_free(default_pool, mem); \
+          (mem) = NULL; \
+       } STMT_END
+
 /* string functions */
 char *i_strdup(const char *str);
 char *i_strdup_empty(const char *str); /* like i_strdup(), but if str == "", return NULL */
index 179fa664b831695348d49882d756b29496e6e8b3..73b47a40e96b8ad4a3c0f9237ccb5c24b3e82b60 100644 (file)
@@ -49,22 +49,24 @@ pool_t pool_datastack_create(void);
 /* 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) \
+       STMT_START { \
+          (pool)->unref(pool); \
+          (pool) = NULL; \
+       } STMT_END
+
+#define p_new(pool, type, count) \
+       ((type *) p_malloc(pool, sizeof(type) * (count)))
 
 #define p_malloc(pool, size) (pool)->malloc(pool, size)
 #define p_realloc(pool, mem, old_size, new_size) \
        (pool)->realloc(pool, mem, old_size, new_size)
-#define p_free(pool, mem) (pool)->free(pool, mem)
-
-#define p_clear(pool) (pool)->clear(pool)
-
-/* Extra macros to make life easier: */
-#define p_new(pool, type, count) \
-       ((type *) p_malloc(pool, sizeof(type) * (count)))
-#define p_free_and_null(pool, rec) \
+#define p_free(pool, mem) \
        STMT_START { \
-          p_free(pool, rec); \
-          (rec) = NULL; \
+          (pool)->free(pool, mem); \
+          (mem) = NULL; \
        } STMT_END
 
+#define p_clear(pool) (pool)->clear(pool)
+
 #endif