gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit 6b89b84d2781a774adbadf272eb90785889b8407
parent c894cf82d59f81529c8f50edec91ca27bd39023d
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 17 Apr 2020 18:21:17 +0200

add GNUNET_freez for #6186

Diffstat:
Msrc/include/gnunet_common.h | 16+++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h @@ -1293,6 +1293,20 @@ GNUNET_is_zero_ (const void *a, /** * @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. * Equivalent to `if (NULL != ptr) GNUNET_free(ptr)`. * @@ -1302,7 +1316,7 @@ GNUNET_is_zero_ (const void *a, do \ { \ void *__x__ = ptr; \ - if (__x__ != NULL) \ + if (NULL != __x__) \ { \ GNUNET_free (__x__); \ } \