summaryrefslogtreecommitdiff
path: root/src/common/util.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-10-27 16:30:52 +0000
committerNick Mathewson <nickm@torproject.org>2008-10-27 16:30:52 +0000
commit0ab45fee73812a90c8714a6a3d99d5727a6733f3 (patch)
tree8349164ed5a3b19612e580012b7dab79c0990ebf /src/common/util.h
parentc53f1f83e78ceca9dc798f8dcc129405e4427c55 (diff)
downloadtor-0ab45fee73812a90c8714a6a3d99d5727a6733f3.tar.gz
tor-0ab45fee73812a90c8714a6a3d99d5727a6733f3.zip
Document some dmalloc stuff and some stupid C tricks.
svn:r17161
Diffstat (limited to 'src/common/util.h')
-rw-r--r--src/common/util.h19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/common/util.h b/src/common/util.h
index dafeb25c1d..0474f0fcf3 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -39,8 +39,11 @@
* security-critical properties.
*/
#error "Sorry; we don't support building with NDEBUG."
-#elif defined(__GNUC__)
-/* Give an int-valued version of !x that won't confuse PREDICT_UNLIKELY. */
+#endif
+
+#if defined(__GNUC__)
+/* Give an int-valued version of !x that won't confuse PREDICT_UNLIKELY,
+ * which does poorly with pointer types on some versions of glibc. */
#define IS_FALSE_AS_INT(x) ((x) == ((typeof(x)) 0))
#else
#define IS_FALSE_AS_INT(x) !(x)
@@ -57,6 +60,11 @@
abort(); \
} STMT_END
+/* If we're building with dmalloc, we want all of our memory allocation
+ * functions to take an extra file/line pair of arguments. If not, not.
+ * We define DMALLOC_PARAMS to the extra parameters to insert in the
+ * function prototypes, and DMALLOC_ARGS to the extra arguments to add
+ * to calls. */
#ifdef USE_DMALLOC
#define DMALLOC_PARAMS , const char *file, const int line
#define DMALLOC_ARGS , _SHORT_FILE_, __LINE__
@@ -91,6 +99,13 @@ extern int dmalloc_free(const char *file, const int line, void *pnt,
} \
STMT_END
#else
+/** Release memory allocated by tor_malloc, tor_realloc, tor_strdup, etc.
+ * Unlike the free() function, tor_free() will still work on NULL pointers,
+ * and it sets the pointer value to NULL after freeing it.
+ *
+ * This is a macro. If you need a function pointer to release memory from
+ * tor_malloc(), use _tor_free().
+ */
#define tor_free(p) STMT_BEGIN \
if (PREDICT_LIKELY((p)!=NULL)) { \
free(p); \