mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-21 08:28:53 +02:00
gsettings: Fix memory leak on error handling path for g_settings_set()
On the warning/critical error handling paths for g_settings_set(), the GVariant value was not ref-sunk, and the schema key was leaked. This won’t affect code in production (unless it’s seriously buggy), but eliminates some leaks from the error testing paths in the GSettings tests. Signed-off-by: Philip Withnall <withnall@endlessm.com> https://bugzilla.gnome.org/show_bug.cgi?id=779265
This commit is contained in:
@@ -1571,6 +1571,7 @@ g_settings_set_value (GSettings *settings,
|
|||||||
g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
|
g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
|
||||||
g_return_val_if_fail (key != NULL, FALSE);
|
g_return_val_if_fail (key != NULL, FALSE);
|
||||||
|
|
||||||
|
g_variant_ref_sink (value);
|
||||||
g_settings_schema_key_init (&skey, settings->priv->schema, key);
|
g_settings_schema_key_init (&skey, settings->priv->schema, key);
|
||||||
|
|
||||||
if (!g_settings_schema_key_type_check (&skey, value))
|
if (!g_settings_schema_key_type_check (&skey, value))
|
||||||
@@ -1580,22 +1581,23 @@ g_settings_set_value (GSettings *settings,
|
|||||||
g_settings_schema_get_id (settings->priv->schema),
|
g_settings_schema_get_id (settings->priv->schema),
|
||||||
g_variant_type_peek_string (skey.type),
|
g_variant_type_peek_string (skey.type),
|
||||||
g_variant_get_type_string (value));
|
g_variant_get_type_string (value));
|
||||||
|
success = FALSE;
|
||||||
return FALSE;
|
}
|
||||||
}
|
else if (!g_settings_schema_key_range_check (&skey, value))
|
||||||
|
|
||||||
if (!g_settings_schema_key_range_check (&skey, value))
|
|
||||||
{
|
{
|
||||||
g_warning ("g_settings_set_value: value for key '%s' in schema '%s' "
|
g_warning ("g_settings_set_value: value for key '%s' in schema '%s' "
|
||||||
"is outside of valid range",
|
"is outside of valid range",
|
||||||
key,
|
key,
|
||||||
g_settings_schema_get_id (settings->priv->schema));
|
g_settings_schema_get_id (settings->priv->schema));
|
||||||
|
success = FALSE;
|
||||||
return FALSE;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
success = g_settings_write_to_backend (settings, &skey, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
success = g_settings_write_to_backend (settings, &skey, value);
|
|
||||||
g_settings_schema_key_clear (&skey);
|
g_settings_schema_key_clear (&skey);
|
||||||
|
g_variant_unref (value);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user