From 5513af2e14aa409be05a91edfc1e0a064f4f643e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jul 2018 16:37:02 +0200 Subject: [PATCH] shared/trivial: add comment to nm_auto_free It's not obvious why we have "nm_auto_free" along "gs_free". Explain it. Also, define the cleanup function first, then the nm-auto macro. --- shared/nm-utils/nm-macros-internal.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 778cc01ab4..259b650181 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -71,9 +71,18 @@ static inline int nm_close (int fd); * nm_auto_free: * * Call free() on a variable location when it goes out of scope. + * This is for pointers that are allocated with malloc() instead of + * g_malloc(). + * + * In practice, since glib 2.45, g_malloc()/g_free() always wraps malloc()/free(). + * See bgo#751592. In that case, it would be safe to free pointers allocated with + * malloc() with gs_free or g_free(). + * + * However, let's never mix them. To free malloc'ed memory, always use + * free() or nm_auto_free. */ -#define nm_auto_free nm_auto(_nm_auto_free_impl) GS_DEFINE_CLEANUP_FUNCTION_VOID (void *, _nm_auto_free_impl, free) +#define nm_auto_free nm_auto(_nm_auto_free_impl) static inline void nm_free_secret (char *secret)