mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 13:13:44 +01:00
Make tor_free only evaluate its input once (at least on gcc and clang)
This commit is contained in:
parent
db024adc90
commit
1d348989b0
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user