From 027ab3efaa4c3e0de12f921df6854373910b06e7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 7 Feb 2015 15:09:48 +0100 Subject: [PATCH] libnm-util: only unref and don't destroy hash in nm_connection_to_hash() The returned hash from nm_connection_to_hash() used to destroy the nested hashes, instead of only unrefing them. --- libnm-util/nm-connection.c | 2 +- libnm-util/tests/test-secrets.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c index a1350f5445..3a929b045f 100644 --- a/libnm-util/nm-connection.c +++ b/libnm-util/nm-connection.c @@ -1241,7 +1241,7 @@ nm_connection_to_hash (NMConnection *connection, NMSettingHashFlags flags) g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); ret = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, (GDestroyNotify) g_hash_table_destroy); + g_free, (GDestroyNotify) g_hash_table_unref); priv = NM_CONNECTION_GET_PRIVATE (connection); diff --git a/libnm-util/tests/test-secrets.c b/libnm-util/tests/test-secrets.c index fb0ad4c7e5..9f0407e4e1 100644 --- a/libnm-util/tests/test-secrets.c +++ b/libnm-util/tests/test-secrets.c @@ -650,20 +650,22 @@ test_update_secrets_whole_connection_bad_setting (void) secrets = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); wsec_hash = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); g_assert (wsec_hash); - g_hash_table_insert (wsec_hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey)); + g_hash_table_insert (wsec_hash, g_strdup (NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), string_to_gvalue (wepkey)); /* Steal the wsec setting hash so it's not deallocated, and stuff it back * in with a different name so we ensure libnm-util is returning the right * error when it finds an entry in the connection hash that doesn't match * any setting in the connection. */ - g_hash_table_steal (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); - g_hash_table_insert (secrets, "asdfasdfasdfasdf", wsec_hash); + g_hash_table_ref (wsec_hash); + g_hash_table_remove (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); + g_hash_table_insert (secrets, g_strdup ("asdfasdfasdfasdf"), wsec_hash); success = nm_connection_update_secrets (connection, NULL, secrets, &error); g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND); g_assert (success == FALSE); + g_hash_table_destroy (secrets); g_object_unref (connection); }