]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
memory-util: introduce erase_and_free() helper
authorLennart Poettering <lennart@poettering.net>
Thu, 8 Aug 2019 17:53:17 +0000 (19:53 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 4 Dec 2019 09:57:59 +0000 (10:57 +0100)
src/basic/memory-util.h

index 46a6907a0cf96baf6832e52080d75eee8144e573..4f92a6434a52ecf2436162052345363ac32a0815 100644 (file)
@@ -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 */