summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-11-17 11:45:47 -0500
committerNick Mathewson <nickm@torproject.org>2017-11-17 11:45:47 -0500
commitc1bdb80aba64ac378784840d231b0db098c05474 (patch)
tree0f6743085a02d78aecce2b0b44251a40daf11293 /src/common
parentfcdec00685608c85161116bdb7408f33094ea3fa (diff)
downloadtor-c1bdb80aba64ac378784840d231b0db098c05474.tar.gz
tor-c1bdb80aba64ac378784840d231b0db098c05474.zip
Add a macro to call a free_ function and clear a variable
Diffstat (limited to 'src/common')
-rw-r--r--src/common/util.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/common/util.h b/src/common/util.h
index 6bc853da26..e11265a5df 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -109,6 +109,14 @@ extern int dmalloc_free(const char *file, const int line, void *pnt,
void tor_log_mallinfo(int severity);
+/* Helper macro: free a variable of type 'type' using type_free_, and
+ * set the variable to NULL. */
+#define FREE_AND_NULL(type, var) \
+ do { \
+ type ## _free_(var); \
+ (var) = NULL; \
+ } while (0)
+
/** Macro: yield a pointer to the field at position <b>off</b> within the
* structure <b>st</b>. Example:
* <pre>