Re: [PATCH 1/2] git-compat-util: add a freez() wrapper around free(x); x = NULL
- From
Christian Couder <christian.couder@gmail.com>
- Date
- Jun 9, 2017, 12:04 UTC
- Message-ID
- <CAP8UFD0w34frARr4AjLQen0oXhFxu4B37e5JKz49oqn5MyxwhA@mail.gmail.com>
- In-Reply-To
- <20170609085346.19974-2-avarab@gmail.com>
On Fri, Jun 9, 2017 at 10:53 AM, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
Show 7 quoted lines
> --- 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)I think we already rely on free(NULL) working, see http://public-inbox.org/git/alpine.DEB.2.20.1608301948310.129229@virtualbox/ for example, so this could just be:
#define freez(p) do { free(p); (p) = NULL; } while (0)and yeah FREEZ() would be even better than freez().