shared: add nm_auto_free_secret macro

This commit is contained in:
Thomas Haller 2017-11-20 11:33:20 +01:00
parent a7c97d58db
commit 97f8d21674

View file

@ -69,6 +69,30 @@ static inline int nm_close (int fd);
#define nm_auto_free nm_auto(_nm_auto_free_impl)
GS_DEFINE_CLEANUP_FUNCTION(void*, _nm_auto_free_impl, free)
static inline void
nm_free_secret (char *secret)
{
if (secret) {
memset (secret, 0, strlen (secret));
g_free (secret);
}
}
static inline void
_nm_auto_free_secret_impl (char **v)
{
nm_free_secret (*v);
}
/**
* nm_auto_free_secret:
*
* Call g_free() on a variable location when it goes out of scope.
* Also, previously, calls memset(loc, 0, strlen(loc)) to clear out
* the secret.
*/
#define nm_auto_free_secret nm_auto(_nm_auto_free_secret_impl)
static inline void
_nm_auto_unset_gvalue_impl (GValue *v)
{