From a26710f4973ef15c48b7f63920977c25dbb3615e Mon Sep 17 00:00:00 2001 From: moritz Date: Thu, 8 Mar 2007 01:12:13 +0000 Subject: [PATCH] Replace the very broken xfree() function with an xfree() macro - the main point was to set ptr to NULL, but the function only set the copy of ptr to NULL. Spotted by Karl Heyes, thanks a lot! git-svn-id: https://svn.xiph.org/trunk/ezstream@12677 0101bb08-14d6-0310-b084-bc0e0c8e3800 --- src/util.c | 13 ------------- src/util.h | 11 ++++++++++- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/util.c b/src/util.c index 06e85f8..0740f26 100644 --- a/src/util.c +++ b/src/util.c @@ -113,19 +113,6 @@ xrealloc(void *ptr, size_t nmemb, size_t size) return (ret); } -void -xfree(void *ptr) -{ - if (ptr == NULL) { - printf("%s: xfree(): Internal error: NULL argument\n", - __progname); - abort(); - } - - free(ptr); - ptr = NULL; -} - char * xstrdup(const char *str) { diff --git a/src/util.h b/src/util.h index 105553b..a19a975 100644 --- a/src/util.h +++ b/src/util.h @@ -20,8 +20,17 @@ void * xmalloc(size_t /* size */); void * xcalloc(size_t /* nmemb */, size_t /* size */); void * xrealloc(void *, size_t /* nmemb */, size_t /* size */); -void xfree(void *); char * xstrdup(const char *); int strrcmp(const char *, const char *); +#define xfree(ptr) do { \ + if ((ptr) == NULL) { \ + printf("%s: xfree(): Internal error: NULL argument\n", \ + __progname); \ + abort(); \ + } \ + free(ptr); \ + (ptr) = NULL; \ +} while (0) + #endif /* __UTIL_H__ */