[collectd] [PATCH] common.h: Make sfree() usable like a function.
Sebastian Harl
sh at tokkee.org
Mon Aug 18 09:30:03 CEST 2008
By putting the code into a "do { } while (0)" loop it is treated like a single
statement and does not break "if () sfree()" like constructs.
Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
src/common.h | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/common.h b/src/common.h
index a5e2167..119cee6 100644
--- a/src/common.h
+++ b/src/common.h
@@ -31,10 +31,12 @@
#endif
#define sfree(ptr) \
- if((ptr) != NULL) { \
- free(ptr); \
- } \
- (ptr) = NULL
+ do { \
+ if((ptr) != NULL) { \
+ free(ptr); \
+ } \
+ (ptr) = NULL; \
+ } while (0)
#define STATIC_ARRAY_SIZE(a) (sizeof (a) / sizeof (*(a)))
--
1.6.0.rc2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20080818/82dfff3d/attachment.pgp
More information about the collectd
mailing list