From: Daniel Wagner Date: Thu, 14 Sep 2023 08:51:41 +0000 (+0200) Subject: util: add cleanup function for generic memory allocations X-Git-Tag: v2.6~28 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=2e1049f13d47c8d9b8874dc75fc78a4cea5ce7e8;p=users%2Fsagi%2Fnvme-cli.git util: add cleanup function for generic memory allocations Introduce a cleanup helper function to free generic memory allocation from malloc, calloc, etc. Signed-off-by: Daniel Wagner --- diff --git a/util/cleanup.h b/util/cleanup.h index 575a25d7..392eb590 100644 --- a/util/cleanup.h +++ b/util/cleanup.h @@ -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