[PATCH 1/2] git-compat-util: add a freez() wrapper around free(x); x = NULL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <avarab@xxxxxxxxx>
---
 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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]