]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
util: add cleanup function for generic memory allocations
authorDaniel Wagner <dwagner@suse.de>
Thu, 14 Sep 2023 08:51:41 +0000 (10:51 +0200)
committerDaniel Wagner <wagi@monom.org>
Wed, 20 Sep 2023 10:04:25 +0000 (12:04 +0200)
Introduce a cleanup helper function to free generic memory allocation
from malloc, calloc, etc.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
util/cleanup.h

index 575a25d7017bedd8b6773cbf5115852fc4ced257..392eb5908b849b2688b9f0f0c66a8d77328cf559 100644 (file)
@@ -16,4 +16,10 @@ DECLARE_CLEANUP_FUNC(name, type)             \
 
 DECLARE_CLEANUP_FUNC(cleanup_charp, char *);
 
+static inline void freep(void *p) {
+        free(*(void**) p);
+}
+
+#define _cleanup_free_ __cleanup__(freep)
+
 #endif