]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add a macro to call a free_ function and clear a variable
authorNick Mathewson <nickm@torproject.org>
Fri, 17 Nov 2017 16:45:47 +0000 (11:45 -0500)
committerNick Mathewson <nickm@torproject.org>
Fri, 17 Nov 2017 16:45:47 +0000 (11:45 -0500)
src/common/util.h

index 6bc853da262652485b0d15d4dac04b327087688b..e11265a5dff97def991353d7d4717d8e62c057e7 100644 (file)
@@ -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>