libnm-util: fix two bugs in nm_setting_bond_get_option()

The function documents that it returns FALSE if idx is out of range,
so don't g_return_val_if_fail() in that case.

Also, free the return value from g_hash_table_get_keys().
This commit is contained in:
Dan Winship
2012-03-02 14:20:55 -05:00
parent 501a389a19
commit fb06cda723

View File

@@ -160,7 +160,6 @@ nm_setting_bond_get_option (NMSettingBond *setting,
const char **out_value) const char **out_value)
{ {
NMSettingBondPrivate *priv; NMSettingBondPrivate *priv;
guint32 num_keys;
GList *keys; GList *keys;
const char *_key = NULL, *_value = NULL; const char *_key = NULL, *_value = NULL;
@@ -168,8 +167,8 @@ nm_setting_bond_get_option (NMSettingBond *setting,
priv = NM_SETTING_BOND_GET_PRIVATE (setting); priv = NM_SETTING_BOND_GET_PRIVATE (setting);
num_keys = nm_setting_bond_get_num_options (setting); if (idx >= nm_setting_bond_get_num_options (setting))
g_return_val_if_fail (idx < num_keys, FALSE); return FALSE;
keys = g_hash_table_get_keys (priv->options); keys = g_hash_table_get_keys (priv->options);
_key = g_list_nth_data (keys, idx); _key = g_list_nth_data (keys, idx);
@@ -180,6 +179,7 @@ nm_setting_bond_get_option (NMSettingBond *setting,
if (out_value) if (out_value)
*out_value = _value; *out_value = _value;
g_list_free (keys);
return TRUE; return TRUE;
} }