summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-12-04 15:18:13 -0500
committerNick Mathewson <nickm@torproject.org>2017-12-08 14:47:19 -0500
commit1d348989b08a3d3c50dfa2600a5e5e2f61fb2b4a (patch)
tree45ad3b679f2265aebcdd6569be0b904fc5fe0de7
parentdb024adc90069ce9961f3993aba1b7372f09d77a (diff)
downloadtor-1d348989b08a3d3c50dfa2600a5e5e2f61fb2b4a.tar.gz
tor-1d348989b08a3d3c50dfa2600a5e5e2f61fb2b4a.zip
Make tor_free only evaluate its input once (at least on gcc and clang)
-rw-r--r--configure.ac1
-rw-r--r--src/common/util.h10
2 files changed, 10 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 93b18a326a..bb34e58831 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1988,7 +1988,6 @@ if test "x$enable_gcc_warnings_advisory" != "xno"; then
-Winvalid-source-encoding
-Winvalid-token-paste
-Wknr-promoted-parameter
- -Wlanguage-extension-token
-Wlarge-by-value-copy
-Wliteral-conversion
-Wliteral-range
diff --git a/src/common/util.h b/src/common/util.h
index 9ed11260dc..e85be57c07 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -80,12 +80,22 @@ extern int dmalloc_free(const char *file, const int line, void *pnt,
* This is a macro. If you need a function pointer to release memory from
* tor_malloc(), use tor_free_().
*/
+#ifdef __GNUC__
+#define tor_free(p) STMT_BEGIN \
+ typeof(&(p)) tor_free__tmpvar = &(p); \
+ if (PREDICT_LIKELY((*tor_free__tmpvar)!=NULL)) { \
+ raw_free(*tor_free__tmpvar); \
+ *tor_free__tmpvar=NULL; \
+ } \
+ STMT_END
+#else
#define tor_free(p) STMT_BEGIN \
if (PREDICT_LIKELY((p)!=NULL)) { \
raw_free(p); \
(p)=NULL; \
} \
STMT_END
+#endif
#endif /* defined(USE_DMALLOC) */
#define tor_malloc(size) tor_malloc_(size DMALLOC_ARGS)