diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index f7945071f1..6631c89684 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -2527,7 +2527,7 @@ test_setting_compare_wireless_cloned_mac_address (void) g_assert_cmpstr ("stable-bia", ==, nm_setting_wireless_get_cloned_mac_address ((NMSettingWireless *) new)); g_object_get (new, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, &str1, NULL); g_assert_cmpstr ("stable-bia", ==, str1); - g_clear_pointer (&str1, g_free); + nm_clear_g_free (&str1); success = nm_setting_compare (old, new, NM_SETTING_COMPARE_FLAG_EXACT); g_assert (!success); diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index e30a50a5ce..fd23a68a30 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -366,6 +366,27 @@ nm_g_object_unref (gpointer obj) g_object_unref (obj); } +/* basically, replaces + * g_clear_pointer (&location, g_free) + * with + * nm_clear_g_free (&location) + * + * Another advantage is that by using a macro and typeof(), it is more + * typesafe and gives you for example a compiler warning when pp is a const + * pointer or points to a const-pointer. + */ +#define nm_clear_g_free(pp) \ + ({ \ + typeof (*(pp)) *_pp = (pp); \ + typeof (**_pp) *_p = *_pp; \ + \ + if (_p) { \ + *_pp = NULL; \ + g_free (_p); \ + } \ + !!_p; \ + }) + static inline gboolean nm_clear_g_source (guint *id) {