From: Lennart Poettering Date: Thu, 8 Aug 2019 17:53:17 +0000 (+0200) Subject: memory-util: introduce erase_and_free() helper X-Git-Tag: v245-rc1~314^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=282bde106652057c5d278a13dd3a0044ca5a9765;p=thirdparty%2Fsystemd.git memory-util: introduce erase_and_free() helper --- diff --git a/src/basic/memory-util.h b/src/basic/memory-util.h index 46a6907a0cf..4f92a6434a5 100644 --- a/src/basic/memory-util.h +++ b/src/basic/memory-util.h @@ -80,14 +80,21 @@ static inline void* explicit_bzero_safe(void *p, size_t l) { void *explicit_bzero_safe(void *p, size_t l); #endif -static inline void erase_and_freep(void *p) { - void *ptr = *(void**) p; +static inline void* erase_and_free(void *p) { + size_t l; + + if (!p) + return NULL; + + l = malloc_usable_size(p); + explicit_bzero_safe(p, l); + free(p); - if (ptr) { - size_t l = malloc_usable_size(ptr); - explicit_bzero_safe(ptr, l); - free(ptr); - } + return NULL; +} + +static inline void erase_and_freep(void *p) { + erase_and_free(*(void**) p); } /* Use with _cleanup_ to erase a single 'char' when leaving scope */