diff options
author | Thomas Haller <thaller@redhat.com> | 2017-11-20 11:33:20 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-11-20 11:37:24 +0100 |
commit | 97f8d2167437e573531e0575741e279fd7e32ffd (patch) | |
tree | 2813f504435fd55c8da327cca08baffa8f3ffa5b | |
parent | a7c97d58dbeef80c328dc1ff24db29aae7485078 (diff) | |
download | NetworkManager-97f8d2167437e573531e0575741e279fd7e32ffd.tar.gz |
shared: add nm_auto_free_secret macro
-rw-r--r-- | shared/nm-utils/nm-macros-internal.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index f4dca4b37a..ce13d3a6fa 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -70,6 +70,30 @@ static inline int nm_close (int fd); 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) { g_value_unset (v); |