From b7f7e71f7ac1692f14b90881807af4031448b078 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 27 Jan 2015 09:41:04 +1100 Subject: [PATCH] Make dealloc entirely a macro allowing the compiler to optimise out the pointer nulling if it's unneeded --- src/libckpool.c | 6 ------ src/libckpool.h | 6 ++++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/libckpool.c b/src/libckpool.c index f2937a05..bed7a816 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -1295,12 +1295,6 @@ void *_ckzalloc(size_t len, const char *file, const char *func, const int line) return ptr; } -void _dealloc(void **ptr) -{ - free(*ptr); - *ptr = NULL; -} - /* Adequate size s==len*2 + 1 must be alloced to use this variant */ void __bin2hex(void *vs, const void *vp, size_t len) { diff --git a/src/libckpool.h b/src/libckpool.h index 1b24d9c2..cb7c1d01 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -177,7 +177,10 @@ static inline void flip_80(void *dest_p, const void *src_p) #define ckalloc(len) _ckalloc(len, __FILE__, __func__, __LINE__) #define ckzalloc(len) _ckzalloc(len, __FILE__, __func__, __LINE__) -#define dealloc(ptr) _dealloc((void *)&(ptr)) +#define dealloc(ptr) do { \ + free(ptr); \ + ptr = NULL; \ +} while (0) #define VASPRINTF(strp, fmt, ...) do { \ if (unlikely(vasprintf(strp, fmt, ##__VA_ARGS__) < 0)) \ @@ -499,7 +502,6 @@ void trail_slash(char **buf); void *_ckalloc(size_t len, const char *file, const char *func, const int line); void *json_ckalloc(size_t size); void *_ckzalloc(size_t len, const char *file, const char *func, const int line); -void _dealloc(void **ptr); extern const int hex2bin_tbl[]; void __bin2hex(void *vs, const void *vp, size_t len); void *bin2hex(const void *vp, size_t len);