summaryrefslogtreecommitdiff
path: root/libnm-core/nm-setting-wired.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-02-07 16:52:43 +0100
committerThomas Haller <thaller@redhat.com>2015-02-09 11:51:05 +0100
commit7a82d64e475fd346638707af76e9f1f63fec204c (patch)
tree1d2b9f1fdb2fd224dfc5a7e999c933225d3c5163 /libnm-core/nm-setting-wired.c
parentf1bfe459eef14fa4d9e71d400362bdcc06a38bdc (diff)
downloadNetworkManager-7a82d64e475fd346638707af76e9f1f63fec204c.tar.gz
libnm: fix memleak in nm_setting_wired_get_s390_option() and refactor
@keys was leaked. Also refactor the function to iterate the hash only once.
Diffstat (limited to 'libnm-core/nm-setting-wired.c')
-rw-r--r--libnm-core/nm-setting-wired.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c
index ac143e45df..2a7479405d 100644
--- a/libnm-core/nm-setting-wired.c
+++ b/libnm-core/nm-setting-wired.c
@@ -434,27 +434,24 @@ nm_setting_wired_get_s390_option (NMSettingWired *setting,
const char **out_key,
const char **out_value)
{
- NMSettingWiredPrivate *priv;
- guint32 num_keys;
- GList *keys;
- const char *_key = NULL, *_value = NULL;
+ const char *_key, *_value;
+ GHashTableIter iter;
+ guint i = 0;
g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
- priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
-
- num_keys = nm_setting_wired_get_num_s390_options (setting);
- g_return_val_if_fail (idx < num_keys, FALSE);
-
- keys = g_hash_table_get_keys (priv->s390_options);
- _key = g_list_nth_data (keys, idx);
- _value = g_hash_table_lookup (priv->s390_options, _key);
-
- if (out_key)
- *out_key = _key;
- if (out_value)
- *out_value = _value;
- return TRUE;
+ g_hash_table_iter_init (&iter, NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_options);
+ while (g_hash_table_iter_next (&iter, (gpointer) &_key, (gpointer) &_value)) {
+ if (i == idx) {
+ if (out_key)
+ *out_key = _key;
+ if (out_value)
+ *out_value = _value;
+ return TRUE;
+ }
+ i++;
+ }
+ g_return_val_if_reached (FALSE);
}
/**