From: Daiki Ueno Date: Wed, 8 Aug 2012 03:24:12 +0000 (+0900) Subject: conf: cleanup GError usage X-Git-Tag: 1.4.99.20121006~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bd4e87f39069331791da09649eb7bf1e675cfefa;p=platform%2Fupstream%2Fibus.git conf: cleanup GError usage - there are missing g_error_free - some code assume error != NULL when setting *error - src/tests/ibus-config.c has unconditional "unset" but it checks the return value BUG=none Review URL: https://codereview.appspot.com/6449103 --- diff --git a/conf/dconf/config.c b/conf/dconf/config.c index 44d7031..dcd8744 100644 --- a/conf/dconf/config.c +++ b/conf/dconf/config.c @@ -254,8 +254,11 @@ ibus_config_dconf_init (IBusConfigDConf *config) NULL); error = NULL; - if (!dconf_client_watch (config->client, DCONF_PREFIX"/", NULL, &error)) - g_warning ("Can not watch dconf path %s", DCONF_PREFIX"/"); + if (!dconf_client_watch (config->client, DCONF_PREFIX"/", NULL, &error)) { + g_warning ("Can not watch dconf path %s: %s", + DCONF_PREFIX"/", error->message); + g_error_free (error); + } #endif config->preserve_name_prefixes = NULL; @@ -285,8 +288,11 @@ ibus_config_dconf_destroy (IBusConfigDConf *config) dconf_client_unwatch_fast (config->client, DCONF_PREFIX"/"); #else GError *error = NULL; - if (!dconf_client_unwatch (config->client, DCONF_PREFIX"/", NULL, &error)) - g_warning ("Can not unwatch dconf path %s", DCONF_PREFIX"/"); + if (!dconf_client_unwatch (config->client, DCONF_PREFIX"/", NULL, &error)) { + g_warning ("Can not unwatch dconf path %s: %s", + DCONF_PREFIX"/", error->message); + g_error_free (error); + } #endif g_object_unref (config->client); @@ -372,8 +378,11 @@ ibus_config_dconf_get_value (IBusConfigService *config, g_free (gkey); if (variant == NULL) { - *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED, - "Config value [%s:%s] does not exist.", section, name); + g_set_error (error, + G_DBUS_ERROR, + G_DBUS_ERROR_FAILED, + "Config value [%s:%s] does not exist.", + section, name); return NULL; } diff --git a/conf/gconf/config.c b/conf/gconf/config.c index 64f1c47..5e81f7d 100644 --- a/conf/gconf/config.c +++ b/conf/gconf/config.c @@ -249,9 +249,10 @@ ibus_config_gconf_set_value (IBusConfigService *config, gv = _to_gconf_value (value); if (gv == NULL) { gchar *str = g_variant_print (value, TRUE); - *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED, - "Can not set config value [%s:%s] to %s.", - section, name, str); + g_set_error (error, + G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Can not set config value [%s:%s] to %s.", + section, name, str); g_free (str); return FALSE; } @@ -280,8 +281,9 @@ ibus_config_gconf_get_value (IBusConfigService *config, g_free (key); if (gv == NULL) { - *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED, - "Config value [%s:%s] does not exist.", section, name); + g_set_error (error, + G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Config value [%s:%s] does not exist.", section, name); return NULL; } @@ -325,13 +327,10 @@ ibus_config_gconf_unset_value (IBusConfigService *config, { gchar *key = g_strdup_printf (GCONF_PREFIX"/%s/%s", section, name); - gconf_client_unset (((IBusConfigGConf *)config)->client, key, error); + gboolean retval = gconf_client_unset (((IBusConfigGConf *)config)->client, key, error); g_free (key); - if (*error != NULL) { - return FALSE; - } - return TRUE; + return retval; } IBusConfigGConf * diff --git a/conf/gconf/main.c b/conf/gconf/main.c index b1100aa..8dc86b5 100644 --- a/conf/gconf/main.c +++ b/conf/gconf/main.c @@ -56,6 +56,7 @@ main (gint argc, gchar **argv) if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("Option parsing failed: %s\n", error->message); + g_error_free (error); exit (-1); } diff --git a/conf/memconf/config.c b/conf/memconf/config.c index dd18f2e..34310c2 100644 --- a/conf/memconf/config.c +++ b/conf/memconf/config.c @@ -182,10 +182,10 @@ ibus_config_memconf_unset_value (IBusConfigService *config, g_variant_new_tuple (NULL, 0)); } else { - if (error && *error) { - *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED, - "Config value [%s:%s] does not exist.", section, name); - } + g_set_error (error, + G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Config value [%s:%s] does not exist.", + section, name); } return retval; } diff --git a/src/tests/ibus-config.c b/src/tests/ibus-config.c index a91d382..5478c53 100644 --- a/src/tests/ibus-config.c +++ b/src/tests/ibus-config.c @@ -270,13 +270,22 @@ change_and_test (IBusConfig *config, { gboolean retval; guint timeout_id; + GVariant *var; data->section = NULL; data->name = NULL; /* Unset won't notify value-changed signal. */ - retval = ibus_config_unset (config, section, name); - g_assert (retval); + var = ibus_config_get_values (config, section); + if (var != NULL) { + GVariant *value = g_variant_lookup_value (var, name, + G_VARIANT_TYPE_VARIANT); + if (value != NULL) { + ibus_config_unset (config, section, name); + g_variant_unref (value); + } + g_variant_unref (var); + } timeout_id = g_timeout_add (1, timeout_cb, data); g_main_loop_run (data->loop);