conf: cleanup GError usage
authorDaiki Ueno <ueno@unixuser.org>
Wed, 8 Aug 2012 03:24:12 +0000 (12:24 +0900)
committerDaiki Ueno <ueno@unixuser.org>
Wed, 8 Aug 2012 03:24:12 +0000 (12:24 +0900)
- 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

conf/dconf/config.c
conf/gconf/config.c
conf/gconf/main.c
conf/memconf/config.c
src/tests/ibus-config.c

index 44d7031..dcd8744 100644 (file)
@@ -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;
     }
 
index 64f1c47..5e81f7d 100644 (file)
@@ -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 *
index b1100aa..8dc86b5 100644 (file)
@@ -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);
     }
 
index dd18f2e..34310c2 100644 (file)
@@ -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;
 }
index a91d382..5478c53 100644 (file)
@@ -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);