summaryrefslogtreecommitdiff
path: root/xmalloc.h
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2013-05-12 13:29:14 +0200
committerTobias Klauser <tklauser@distanz.ch>2013-05-12 13:29:14 +0200
commit06d60f51149ef960110431b228828c7bbc84e74c (patch)
tree7cebcc8f29513c62a50de730f80784bcd97f8dfb /xmalloc.h
parente12a08652f7d2b92e75d8dd7b8528d1d0e69b2a8 (diff)
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 <tklauser@distanz.ch>
Diffstat (limited to 'xmalloc.h')
-rw-r--r--xmalloc.h17
1 files changed, 11 insertions, 6 deletions
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 */