From 06d60f51149ef960110431b228828c7bbc84e74c Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 12 May 2013 13:29:14 +0200 Subject: xmalloc: Make xfree a two part macro/inline This way the coverity scanner will no longer complain about dereference before NULL checks right before xfree(). Signed-off-by: Tobias Klauser --- xmalloc.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'xmalloc.h') diff --git a/xmalloc.h b/xmalloc.h index 53a88b6..3285eb3 100644 --- a/xmalloc.h +++ b/xmalloc.h @@ -24,12 +24,17 @@ extern char *xstrdup(const char *str) __hidden; extern char *xstrndup(const char *str, size_t size) __hidden; extern int xdup(int fd) __hidden; -#define xfree(ptr) \ -do { \ - if (unlikely((ptr) == NULL)) \ - panic("xfree: NULL pointer given as argument\n"); \ - free((ptr)); \ - (ptr) = NULL; \ +static inline void __xfree(void *ptr) +{ + if (unlikely((ptr) == NULL)) + panic("xfree: NULL pointer given as argument\n"); + free(ptr); +} + +#define xfree(ptr) \ +do { \ + __xfree(ptr); \ + (ptr) = NULL; \ } while (0) #endif /* XMALLOC_H */ -- cgit v1.2.3-54-g00ecf