From 6b89b84d2781a774adbadf272eb90785889b8407 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 17 Apr 2020 18:21:17 +0200 Subject: add GNUNET_freez for #6186 --- src/include/gnunet_common.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/include') diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 6a4e21823..78aeb3de7 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -1291,6 +1291,20 @@ GNUNET_is_zero_ (const void *a, */ #define GNUNET_free(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__) +/** + * @ingroup memory + * Wrapper around free. Frees the memory referred to by ptr and sets ptr to NULL. + * Note that it is generally better to free memory that was + * allocated with #GNUNET_array_grow using #GNUNET_array_grow(mem, size, 0) instead of #GNUNET_freez. + * + * @param ptr location where to free the memory. ptr must have + * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. + */ +#define GNUNET_freez(ptr) do { \ + GNUNET_xfree_ (ptr, __FILE__, __LINE__); \ + ptr = NULL; \ +} while (0) + /** * @ingroup memory * Free the memory pointed to by ptr if ptr is not NULL. @@ -1302,7 +1316,7 @@ GNUNET_is_zero_ (const void *a, do \ { \ void *__x__ = ptr; \ - if (__x__ != NULL) \ + if (NULL != __x__) \ { \ GNUNET_free (__x__); \ } \ -- cgit v1.2.3