From 426a4c9d50e1a5b7187dfdf82ee423768fe1c6da Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 2 Sep 2020 17:36:08 +0200 Subject: [PATCH] all: replace cleanup macro "gs_unref_keyfile" by "nm_auto_unref_keyfile" --- clients/cli/connections.c | 2 +- clients/common/nm-secret-agent-simple.c | 2 +- dispatcher/tests/test-dispatcher-envp.c | 2 +- libnm-core/nm-keyfile/nm-keyfile.c | 2 +- libnm-core/tests/test-keyfile.c | 12 ++++++------ libnm-core/tests/test-setting.c | 12 ++++++------ shared/nm-glib-aux/nm-macros-internal.h | 8 -------- shared/nm-utils/nm-test-utils.h | 6 +++--- src/initrd/nm-initrd-generator.c | 2 +- src/nm-config-data.c | 2 +- src/nm-config.c | 12 ++++++------ src/settings/plugins/keyfile/nms-keyfile-reader.c | 2 +- src/settings/plugins/keyfile/nms-keyfile-utils.c | 4 ++-- src/settings/plugins/keyfile/nms-keyfile-writer.c | 2 +- .../plugins/keyfile/tests/test-keyfile-settings.c | 14 +++++++------- 15 files changed, 38 insertions(+), 46 deletions(-) diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 9ff6a393ec..3878264b2d 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -6322,7 +6322,7 @@ load_history_cmds (const char *uuid) static void save_history_cmds (const char *uuid) { - gs_unref_keyfile GKeyFile *kf = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; gs_free_error GError *error = NULL; gs_free char *filename = NULL; gs_free char *data = NULL; diff --git a/clients/common/nm-secret-agent-simple.c b/clients/common/nm-secret-agent-simple.c index 53217e6f33..290a9c3063 100644 --- a/clients/common/nm-secret-agent-simple.c +++ b/clients/common/nm-secret-agent-simple.c @@ -550,7 +550,7 @@ _auth_dialog_exited (GPid pid, int status, gpointer user_data) RequestData *request = data->request; GPtrArray *secrets = data->secrets; NMSettingVpn *s_vpn = nm_connection_get_setting_vpn (request->connection); - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; gs_strfreev char **groups = NULL; gs_free char *title = NULL; gs_free char *message = NULL; diff --git a/dispatcher/tests/test-dispatcher-envp.c b/dispatcher/tests/test-dispatcher-envp.c index 240b89513f..528a0027c6 100644 --- a/dispatcher/tests/test-dispatcher-envp.c +++ b/dispatcher/tests/test-dispatcher-envp.c @@ -395,7 +395,7 @@ get_dispatcher_file (const char *file, GHashTable **out_env, GError **error) { - gs_unref_keyfile GKeyFile *kf = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; gs_strfreev char **keys = NULL; char **iter; diff --git a/libnm-core/nm-keyfile/nm-keyfile.c b/libnm-core/nm-keyfile/nm-keyfile.c index c1fcae3d28..a51d75ab6e 100644 --- a/libnm-core/nm-keyfile/nm-keyfile.c +++ b/libnm-core/nm-keyfile/nm-keyfile.c @@ -4093,7 +4093,7 @@ nm_keyfile_write (NMConnection *connection, void *user_data, GError **error) { - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; KeyfileWriterInfo info; gs_free NMSetting **settings = NULL; guint i, j, n_settings = 0; diff --git a/libnm-core/tests/test-keyfile.c b/libnm-core/tests/test-keyfile.c index c9ec51f01b..ec289b7cd8 100644 --- a/libnm-core/tests/test-keyfile.c +++ b/libnm-core/tests/test-keyfile.c @@ -66,7 +66,7 @@ do_test_encode_key_full (GKeyFile *kf, const char *name, const char *key, const static void test_encode_key (void) { - gs_unref_keyfile GKeyFile *kf = g_key_file_new (); + nm_auto_unref_keyfile GKeyFile *kf = g_key_file_new (); do_test_encode_key_identity (kf, "a"); do_test_encode_key_bijection (kf, "", "\\00"); @@ -209,7 +209,7 @@ _keyfile_convert (NMConnection **con, NMConnection *c0; GKeyFile *k0; gs_unref_object NMConnection *c0_k1_c2 = NULL, *k0_c1 = NULL, *k0_c1_k2_c3 = NULL; - gs_unref_keyfile GKeyFile *k0_c1_k2 = NULL, *c0_k1 = NULL, *c0_k1_c2_k3 = NULL; + nm_auto_unref_keyfile GKeyFile *k0_c1_k2 = NULL, *c0_k1 = NULL, *c0_k1_c2_k3 = NULL; /* convert from @con to @keyfile and check that we can make * full round trips and obtaining the same result. */ @@ -654,7 +654,7 @@ test_team_conf_read_invalid (void) static void test_user_1 (void) { - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; gs_unref_object NMConnection *con = NULL; NMSettingUser *s_user; @@ -721,7 +721,7 @@ test_user_1 (void) static void test_vpn_1 (void) { - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; gs_unref_object NMConnection *con = NULL; NMSettingVpn *s_vpn; @@ -748,7 +748,7 @@ test_vpn_1 (void) static void test_bridge_vlans (void) { - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; gs_unref_object NMConnection *con = NULL; NMSettingBridge *s_bridge; NMBridgeVlan *vlan; @@ -798,7 +798,7 @@ test_bridge_vlans (void) static void test_bridge_port_vlans (void) { - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; gs_unref_object NMConnection *con = NULL; NMSettingBridgePort *s_port; NMBridgeVlan *vlan; diff --git a/libnm-core/tests/test-setting.c b/libnm-core/tests/test-setting.c index 6bf1fdb1e4..60da507ee7 100644 --- a/libnm-core/tests/test-setting.c +++ b/libnm-core/tests/test-setting.c @@ -1562,7 +1562,7 @@ test_ethtool_features (void) gs_unref_object NMConnection *con3 = NULL; gs_unref_variant GVariant *variant = NULL; gs_free_error GError *error = NULL; - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; NMSettingConnection *s_con; NMSettingEthtool *s_ethtool; NMSettingEthtool *s_ethtool2; @@ -1636,7 +1636,7 @@ test_ethtool_coalesce (void) gs_unref_object NMConnection *con3 = NULL; gs_unref_variant GVariant *variant = NULL; gs_free_error GError *error = NULL; - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; NMSettingConnection *s_con; NMSettingEthtool *s_ethtool; NMSettingEthtool *s_ethtool2; @@ -1721,7 +1721,7 @@ test_ethtool_ring (void) gs_unref_object NMConnection *con3 = NULL; gs_unref_variant GVariant *variant = NULL; gs_free_error GError *error = NULL; - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; NMSettingConnection *s_con; NMSettingEthtool *s_ethtool; NMSettingEthtool *s_ethtool2; @@ -3369,7 +3369,7 @@ test_roundtrip_conversion (gconstpointer test_data) * when converting @con to keyfile. Write @con to keyfile and compare the expected result * literally. */ { - gs_unref_keyfile GKeyFile *kf = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; kf = nm_keyfile_write (con, NM_KEYFILE_HANDLER_FLAGS_NONE, NULL, NULL, &error); nmtst_assert_success (kf, error); @@ -3464,7 +3464,7 @@ test_roundtrip_conversion (gconstpointer test_data) nmtst_assert_connection_equals (con, nmtst_get_rand_bool (), con2, nmtst_get_rand_bool ()); { - gs_unref_keyfile GKeyFile *kf = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; kf = nm_keyfile_write (con2, NM_KEYFILE_HANDLER_FLAGS_NONE, NULL, NULL, &error); nmtst_assert_success (kf, error); @@ -3752,7 +3752,7 @@ test_empty_setting (void) gs_unref_object NMConnection *con2 = NULL; NMSettingBluetooth *s_bt; NMSettingGsm *s_gsm; - gs_unref_keyfile GKeyFile *kf = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; gs_free_error GError *error = NULL; con = nmtst_create_minimal_connection ("bt-empty-gsm", "dca3192a-f2dc-48eb-b806-d0ff788f122c", NM_SETTING_BLUETOOTH_SETTING_NAME, NULL); diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index 2b7c1bbfa1..c8017c69ce 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -133,14 +133,6 @@ NM_AUTO_DEFINE_FCN0 (char **, gs_local_strfreev, g_strfreev); #define gs_free_error nm_auto(gs_local_free_error) NM_AUTO_DEFINE_FCN0 (GError *, gs_local_free_error, g_error_free); -/** - * gs_unref_keyfile: - * - * Call g_key_file_unref() on a variable location when it goes out of scope. - */ -#define gs_unref_keyfile nm_auto(gs_local_keyfile_unref) -NM_AUTO_DEFINE_FCN0 (GKeyFile *, gs_local_keyfile_unref, g_key_file_unref); - /*****************************************************************************/ #include "nm-glib.h" diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index 8247fbfc08..08ba9166c2 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -1973,7 +1973,7 @@ nmtst_assert_connection_equals (NMConnection *a, gboolean normalize_a, NMConnect #ifdef __NM_KEYFILE_INTERNAL_H__ { - gs_unref_keyfile GKeyFile *kf_a = NULL, *kf_b = NULL; + nm_auto_unref_keyfile GKeyFile *kf_a = NULL, *kf_b = NULL; gs_free char *str_a = NULL, *str_b = NULL; kf_a = nm_keyfile_write (a, NM_KEYFILE_HANDLER_FLAGS_NONE, NULL, NULL, NULL); @@ -2300,7 +2300,7 @@ nmtst_assert_hwaddr_equals (gconstpointer hwaddr1, gssize hwaddr1_len, const cha static inline NMConnection * nmtst_create_connection_from_keyfile (const char *keyfile_str, const char *full_filename) { - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; gs_free_error GError *error = NULL; gboolean success; NMConnection *con; @@ -2532,7 +2532,7 @@ nmtst_variant_from_string (const GVariantType *variant_type, static inline void nmtst_keyfile_assert_data (GKeyFile *kf, const char *data, gssize data_len) { - gs_unref_keyfile GKeyFile *kf2 = NULL; + nm_auto_unref_keyfile GKeyFile *kf2 = NULL; gs_free_error GError *error = NULL; gs_free char *d1 = NULL; gs_free char *d2 = NULL; diff --git a/src/initrd/nm-initrd-generator.c b/src/initrd/nm-initrd-generator.c index d9f3280ecf..fdcbc283fd 100644 --- a/src/initrd/nm-initrd-generator.c +++ b/src/initrd/nm-initrd-generator.c @@ -25,7 +25,7 @@ output_conn (gpointer key, gpointer value, gpointer user_data) const char *basename = key; NMConnection *connection = value; char *connections_dir = user_data; - gs_unref_keyfile GKeyFile *file = NULL; + nm_auto_unref_keyfile GKeyFile *file = NULL; gs_free char *data = NULL; gs_free_error GError *error = NULL; gsize len; diff --git a/src/nm-config-data.c b/src/nm-config-data.c index ea3aed470b..801a0065e5 100644 --- a/src/nm-config-data.c +++ b/src/nm-config-data.c @@ -219,7 +219,7 @@ nm_config_data_get_plugins (const NMConfigData *self, gboolean allow_default) list = g_key_file_get_string_list (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NULL, &error); if ( nm_keyfile_error_is_not_found (error) && allow_default) { - gs_unref_keyfile GKeyFile *kf = nm_config_create_keyfile (); + nm_auto_unref_keyfile GKeyFile *kf = nm_config_create_keyfile (); /* let keyfile split the default string according to its own escaping rules. */ g_key_file_set_value (kf, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NM_CONFIG_DEFAULT_MAIN_PLUGINS); diff --git a/src/nm-config.c b/src/nm-config.c index e0b9ce3ce7..06e36b71ae 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -900,7 +900,7 @@ read_config (GKeyFile *keyfile, GPtrArray *warnings, GError **error) { - gs_unref_keyfile GKeyFile *kf = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; gs_strfreev char **groups = NULL; gs_free char *path_free = NULL; gsize ngroups; @@ -1210,7 +1210,7 @@ read_entire_config (const NMConfigCmdLineOptions *cli, GPtrArray *warnings, GError **error) { - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; gs_unref_ptrarray GPtrArray *system_confs = NULL; gs_unref_ptrarray GPtrArray *confs = NULL; gs_unref_ptrarray GPtrArray *run_confs = NULL; @@ -2310,7 +2310,7 @@ nm_config_device_state_load (int ifindex) { NMConfigDeviceStateData *device_state; char path[NM_STRLEN (NM_CONFIG_DEVICE_STATE_DIR"/") + DEVICE_STATE_FILENAME_LEN_MAX + 1]; - gs_unref_keyfile GKeyFile *kf = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; const char *nm_owned_str; g_return_val_if_fail (ifindex > 0, NULL); @@ -2397,7 +2397,7 @@ nm_config_device_state_write (int ifindex, { char path[NM_STRLEN (NM_CONFIG_DEVICE_STATE_DIR"/") + DEVICE_STATE_FILENAME_LEN_MAX + 1]; GError *local = NULL; - gs_unref_keyfile GKeyFile *kf = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (!connection_uuid || *connection_uuid, FALSE); @@ -2782,8 +2782,8 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) { NMConfig *self = NM_CONFIG (initable); NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (self); - gs_unref_keyfile GKeyFile *keyfile = NULL; - gs_unref_keyfile GKeyFile *keyfile_intern = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile_intern = NULL; gs_free char *config_main_file = NULL; gs_free char *config_description = NULL; gs_strfreev char **no_auto_default = NULL; diff --git a/src/settings/plugins/keyfile/nms-keyfile-reader.c b/src/settings/plugins/keyfile/nms-keyfile-reader.c index 0e9ad5fa48..bb6f90e63f 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-reader.c +++ b/src/settings/plugins/keyfile/nms-keyfile-reader.c @@ -161,7 +161,7 @@ nms_keyfile_reader_from_file (const char *full_filename, NMTernary *out_shadowed_owned, GError **error) { - gs_unref_keyfile GKeyFile *key_file = NULL; + nm_auto_unref_keyfile GKeyFile *key_file = NULL; NMConnection *connection = NULL; GError *verify_error = NULL; diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.c b/src/settings/plugins/keyfile/nms-keyfile-utils.c index e3c3969146..f33653161e 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-utils.c +++ b/src/settings/plugins/keyfile/nms-keyfile-utils.c @@ -127,7 +127,7 @@ nms_keyfile_nmmeta_read (const char *dirname, return FALSE; if (S_ISREG (st->st_mode)) { - gs_unref_keyfile GKeyFile *kf = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; gs_free char *v_uuid = NULL; kf = g_key_file_new (); @@ -243,7 +243,7 @@ nms_keyfile_nmmeta_write (const char *dirname, full_filename = g_strndup (full_filename_tmp, strlen (full_filename_tmp) - 1); if (shadowed_storage) { - gs_unref_keyfile GKeyFile *kf = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; gs_free char *contents = NULL; gsize length; diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c index feea606517..2676f5bfd8 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-writer.c +++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c @@ -185,7 +185,7 @@ _internal_write_connection (NMConnection *connection, gboolean *out_reread_same, GError **error) { - gs_unref_keyfile GKeyFile *kf_file = NULL; + nm_auto_unref_keyfile GKeyFile *kf_file = NULL; gs_free char *kf_content_buf = NULL; gsize kf_content_len; gs_free char *path = NULL; diff --git a/src/settings/plugins/keyfile/tests/test-keyfile-settings.c b/src/settings/plugins/keyfile/tests/test-keyfile-settings.c index 98820272c1..70b0735afd 100644 --- a/src/settings/plugins/keyfile/tests/test-keyfile-settings.c +++ b/src/settings/plugins/keyfile/tests/test-keyfile-settings.c @@ -802,7 +802,7 @@ test_write_string_ssid (void) gs_free char *testfile = NULL; GBytes *ssid; unsigned char tmpssid[] = { 65, 49, 50, 51, 32, 46, 92, 46, 36, 37, 126, 93 }; - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; connection = nm_simple_connection_new (); @@ -880,7 +880,7 @@ test_write_intlist_ssid (void) GBytes *ssid; unsigned char tmpssid[] = { 65, 49, 50, 51, 0, 50, 50 }; gs_free_error GError *error = NULL; - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; int *intlist; gsize len = 0, i; @@ -979,7 +979,7 @@ test_write_intlike_ssid (void) GBytes *ssid; unsigned char tmpssid[] = { 49, 48, 49 }; gs_free_error GError *error = NULL; - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; char *tmp; connection = nm_simple_connection_new (); @@ -1037,7 +1037,7 @@ test_write_intlike_ssid_2 (void) GBytes *ssid; unsigned char tmpssid[] = { 49, 49, 59, 49, 50, 59, 49, 51, 59}; gs_free_error GError *error = NULL; - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; char *tmp; connection = nm_simple_connection_new (); @@ -1533,7 +1533,7 @@ test_write_wired_8021x_tls_connection_path (void) char *tmp, *tmp2; gboolean success; gs_free char *testfile = NULL; - gs_unref_keyfile GKeyFile *keyfile = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; gboolean relative = FALSE; gboolean reread_same = FALSE; @@ -1966,7 +1966,7 @@ test_write_new_wired_group_name (void) { NMTST_UUID_INIT (uuid); gs_unref_object NMConnection *connection = NULL; - gs_unref_keyfile GKeyFile *kf = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; gs_free char *testfile = NULL; @@ -2044,7 +2044,7 @@ test_write_new_wireless_group_names (void) { NMTST_UUID_INIT (uuid); gs_unref_object NMConnection *connection = NULL; - gs_unref_keyfile GKeyFile *kf = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec;