summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert James Kaes <rjkaes@users.sourceforge.net>2003-05-31 23:04:15 +0000
committerRobert James Kaes <rjkaes@users.sourceforge.net>2003-05-31 23:04:15 +0000
commitea50171a95fbb87710615682bdf2974853a42211 (patch)
tree24190da64353689de3c73a1fc25f8b3091171745
parent77ca1c8ce0df4d7733bb5a382ca8c18adba93e1c (diff)
downloadtinyproxy-ea50171a95fbb87710615682bdf2974853a42211.tar.gz
tinyproxy-ea50171a95fbb87710615682bdf2974853a42211.zip
Changed the safefree() macro to make it safe to use a conditional
statement, and also safe to use with a rvalue that has a side effect. [Bug fix recommended by Peter da Silva]
Diffstat (limited to '')
-rw-r--r--src/heap.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/heap.h b/src/heap.h
index 1bfe47a..5431e11 100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -1,4 +1,4 @@
-/* $Id: heap.h,v 1.2 2002-05-26 18:56:06 rjkaes Exp $
+/* $Id: heap.h,v 1.3 2003-05-31 23:04:15 rjkaes Exp $
*
* See 'heap.c' for a detailed description.
*
@@ -36,13 +36,21 @@ extern char *debugging_strdup(const char* s, const char* file,
# define safecalloc(x, y) debugging_calloc(x, y, __FILE__, __LINE__)
# define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__)
# define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__)
-# define safefree(x) debugging_free(x, __FILE__, __LINE__); (x) = NULL
# define safestrdup(x) debugging_strdup(x, __FILE__, __LINE__)
+# define safefree(x) do { \
+void **__safefree_tmp = (void *)&(x); \
+debugging_free(*__safefree_tmp, __FILE__, __LINE__); \
+*__safefree_tmp = NULL; \
+} while (0)
#else
# define safecalloc(x, y) calloc(x, y)
# define safemalloc(x) malloc(x)
# define saferealloc(x, y) realloc(x, y)
-# define safefree(x) free(x); (x) = NULL
+# define safefree(x) do { \
+void **__safefree_tmp = (void *)&(x); \
+free(*__safefree_tmp); \
+*__safefree_tmp = NULL; \
+} while (0)
# define safestrdup(x) strdup(x)
#endif