summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-07-11 14:06:28 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2018-07-11 16:16:22 +0200
commit634b2d1ce2687d724add893836f06beacd5a3700 (patch)
tree7fe4c740c28458b00aaeda15413dc04100947a56
parentfe07d6a404c05cea7d5e13fca8751ac82a7cff0f (diff)
downloadNetworkManager-634b2d1ce2687d724add893836f06beacd5a3700.tar.gz
shared: add nm_auto_vfree macro
This really is the same as gs_strfreev / g_strfreev(). However, the difference is, that the former has the notion of freeing strv arrays (char **), while this in general frees an array of pointers. Implementation-wise, they are the same.
-rw-r--r--shared/nm-utils/nm-macros-internal.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h
index e60bacebdc..5de0536796 100644
--- a/shared/nm-utils/nm-macros-internal.h
+++ b/shared/nm-utils/nm-macros-internal.h
@@ -161,6 +161,23 @@ _nm_auto_unref_gsource (GSource **ptr)
}
#define nm_auto_unref_gsource nm_auto(_nm_auto_unref_gsource)
+static inline void
+_nm_auto_freev (gpointer ptr)
+{
+ gpointer **p = ptr;
+ gpointer *_ptr;
+
+ if (*p) {
+ for (_ptr = *p; *_ptr; _ptr++)
+ g_free (*_ptr);
+ g_free (*p);
+ }
+}
+/* g_free a NULL terminated array of pointers, with also freeing each
+ * pointer with g_free(). It essentially does the same as
+ * gs_strfreev / g_strfreev(), but not restricted to strv arrays. */
+#define nm_auto_freev nm_auto(_nm_auto_freev)
+
/*****************************************************************************/
/* http://stackoverflow.com/a/11172679 */