diff options
author | Ted Gould <ted@gould.cx> | 2011-03-23 10:48:04 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2011-03-23 10:48:04 -0500 |
commit | 2916c6939b6eee45dc5876d6f06cfba2b8635163 (patch) | |
tree | f4136454d87247f4268ee832d3588ec4aeb88852 /libdbusmenu-glib | |
parent | aebf305c5893813f577378a105f12ab8f86ca17b (diff) | |
parent | f297caeae1f563fe023cfd57cd7b3d05d8d32d47 (diff) | |
download | libdbusmenu-2916c6939b6eee45dc5876d6f06cfba2b8635163.tar.gz libdbusmenu-2916c6939b6eee45dc5876d6f06cfba2b8635163.tar.bz2 libdbusmenu-2916c6939b6eee45dc5876d6f06cfba2b8635163.zip |
Switch to using iter_loop to protect from NULL variants
Diffstat (limited to 'libdbusmenu-glib')
-rw-r--r-- | libdbusmenu-glib/client.c | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 2976436..20b91f1 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -599,9 +599,10 @@ get_properties_callback (GObject *obj, GAsyncResult * res, gpointer user_data) /* Callback all the folks we can find */ GVariant * child = g_variant_get_child_value(params, 0); - GVariantIter * iter = g_variant_iter_new(child); + GVariantIter iter; + g_variant_iter_init(&iter, child); g_variant_unref(child); - while ((child = g_variant_iter_next_value(iter)) != NULL) { + while ((child = g_variant_iter_next_value(&iter)) != NULL) { if (g_strcmp0(g_variant_get_type_string(child), "(ia{sv})") != 0) { g_warning("Properties return signature is not '(ia{sv})' it is '%s'", g_variant_get_type_string(child)); g_variant_unref(child); @@ -631,7 +632,6 @@ get_properties_callback (GObject *obj, GAsyncResult * res, gpointer user_data) g_variant_unref(properties); g_variant_unref(child); } - g_variant_iter_free(iter); g_variant_unref(params); /* Provide errors for those who we can't */ @@ -1153,7 +1153,7 @@ menuproxy_prop_changed_cb (GDBusProxy * proxy, GVariant * properties, GStrv inva GVariantIter iters; gchar * key; GVariant * value; g_variant_iter_init(&iters, properties); - while (g_variant_iter_next(&iters, "{sv}", &key, &value)) { + while (g_variant_iter_loop(&iters, "{sv}", &key, &value)) { if (g_strcmp0(key, "TextDirection") == 0) { if (g_variant_is_of_type(value, G_VARIANT_TYPE_VARIANT)) { GVariant * tmp = g_variant_get_variant(value); @@ -1181,9 +1181,6 @@ menuproxy_prop_changed_cb (GDBusProxy * proxy, GVariant * properties, GStrv inva priv->icon_dirs = g_variant_dup_strv(value, NULL); dirs_changed = TRUE; } - - g_variant_unref(value); - g_free(key); } if (olddir != priv->text_direction) { @@ -1258,10 +1255,9 @@ menuproxy_signal_cb (GDBusProxy * proxy, gchar * sender, gchar * signal, GVarian g_variant_iter_init(&properties, propv); gchar * property; - while (g_variant_iter_next(&properties, "s", &property)) { + while (g_variant_iter_loop(&properties, "s", &property)) { /* g_debug("Removing property '%s' on %d", property, id); */ dbusmenu_menuitem_property_remove(menuitem, property); - g_free(property); } g_variant_unref(ritem); g_variant_unref(propv); @@ -1284,15 +1280,20 @@ menuproxy_signal_cb (GDBusProxy * proxy, gchar * sender, gchar * signal, GVarian gchar * property; GVariant * value; - while (g_variant_iter_next(&properties, "{sv}", &property, &value)) { + while (g_variant_iter_loop(&properties, "{sv}", &property, &value)) { GVariant * internalvalue = value; if (G_LIKELY(g_variant_is_of_type(value, G_VARIANT_TYPE_VARIANT))) { /* Unboxing if needed */ internalvalue = g_variant_get_variant(value); - g_variant_unref(value); } + id_prop_update(proxy, id, property, internalvalue, client); - g_variant_unref(internalvalue); + + if (internalvalue != value) { + /* If we unboxed, we need to drop it, otherwise the + iter_loop function will unref for us */ + g_variant_unref(internalvalue); + } } g_variant_unref(propv); g_variant_unref(item); @@ -1336,19 +1337,16 @@ menuitem_get_properties_cb (GVariant * properties, GError * error, gpointer data return; } - GVariantIter * iter = g_variant_iter_new(properties); + GVariantIter iter; gchar * key; GVariant * value; - while (g_variant_iter_next(iter, "{sv}", &key, &value)) { - dbusmenu_menuitem_property_set_variant(item, key, value); + g_variant_iter_init(&iter, properties); - g_variant_unref(value); - g_free(key); + while (g_variant_iter_loop(&iter, "{sv}", &key, &value)) { + dbusmenu_menuitem_property_set_variant(item, key, value); } - g_variant_iter_free(iter); - g_object_unref(data); return; @@ -1714,20 +1712,16 @@ parse_layout_xml(DbusmenuClient * client, GVariant * layout, DbusmenuMenuitem * all other properties. */ child_props = g_variant_get_child_value(child, 1); g_variant_iter_init(&iter, child_props); - while (g_variant_iter_next(&iter, "{sv}", &prop, &value)) { + while (g_variant_iter_loop(&iter, "{sv}", &prop, &value)) { if (g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_TYPE) == 0) { dbusmenu_menuitem_property_set_variant(childmi, prop, value); } - g_free(prop); - g_variant_unref(value); } /* Now go through and do all the properties. */ g_variant_iter_init(&iter, child_props); - while (g_variant_iter_next(&iter, "{sv}", &prop, &value)) { + while (g_variant_iter_loop(&iter, "{sv}", &prop, &value)) { dbusmenu_menuitem_property_set_variant(childmi, prop, value); - g_free(prop); - g_variant_unref(value); } g_variant_unref(child_props); } |