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.
This commit is contained in:
Thomas Haller 2018-07-11 14:06:28 +02:00 committed by Beniamino Galvani
parent fe07d6a404
commit 634b2d1ce2

View file

@ -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 */