Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
GSettings: two memory use fixes
Browse files Browse the repository at this point in the history
First, correct a rather dubious case of accessing a GSettingsSchemaKey
after clearing it.  This was technically okay because only the key name
was accessed (and it is not owned by the struct) but it looks very
wrong.

Second, have g_settings_backend_write() sink the passed in GVariant*.
Not all backends get this right, and I'm starting to like the pattern of
virtual function wrappers being responsible for sinking the parameters
that they are documented as consuming.
  • Loading branch information
allisonkarlitskaya committed Jan 27, 2012
1 parent 8e763ae commit da38670
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion gio/gsettings.c
Expand Up @@ -1322,6 +1322,7 @@ g_settings_set_value (GSettings *settings,
GVariant *value)
{
GSettingsSchemaKey skey;
gboolean success;

g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
g_return_val_if_fail (key != NULL, FALSE);
Expand Down Expand Up @@ -1349,9 +1350,10 @@ g_settings_set_value (GSettings *settings,
return FALSE;
}

success = g_settings_write_to_backend (settings, &skey, value);
g_settings_schema_key_clear (&skey);

return g_settings_write_to_backend (settings, &skey, value);
return success;
}

/**
Expand Down
8 changes: 7 additions & 1 deletion gio/gsettingsbackend.c
Expand Up @@ -772,8 +772,14 @@ g_settings_backend_write (GSettingsBackend *backend,
GVariant *value,
gpointer origin_tag)
{
return G_SETTINGS_BACKEND_GET_CLASS (backend)
gboolean success;

g_variant_ref_sink (value);
success = G_SETTINGS_BACKEND_GET_CLASS (backend)
->write (backend, key, value, origin_tag);
g_variant_unref (value);

return success;
}

/*< private >
Expand Down

0 comments on commit da38670

Please sign in to comment.