Add a freez() wrapper for the common pattern of freeing a pointer and
assigning NULL to it right afterwards.

The implementation is the same as the (currently unused) XDL_PTRFREE
macro in xdiff/xmacros.h added in commit 3443546f6e ("Use a *real*
built-in diff generator", 2006-03-24).

Signed-off-by: Ævar Arnfjörð Bjarmason <ava...@gmail.com>
---
 git-compat-util.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/git-compat-util.h b/git-compat-util.h
index 4b7dcf21ad..21e3710755 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -787,6 +787,7 @@ extern char *xstrdup(const char *str);
 extern void *xmalloc(size_t size);
 extern void *xmallocz(size_t size);
 extern void *xmallocz_gently(size_t size);
+#define freez(p) do { if (p) { free(p); (p) = NULL; } } while (0)
 extern void *xmemdupz(const void *data, size_t len);
 extern char *xstrndup(const char *str, size_t len);
 extern void *xrealloc(void *ptr, size_t size);
-- 
2.13.0.506.g27d5fe0cd

Reply via email to