Merge lp:~charlesk/indicator-appmenu/fix-953479 into lp:indicator-appmenu/0.4

Proposed by Charles Kerr
Status: Merged
Approved by: Charles Kerr
Approved revision: 182
Merged at revision: 180
Proposed branch: lp:~charlesk/indicator-appmenu/fix-953479
Merge into: lp:indicator-appmenu/0.4
Diff against target: 44 lines (+15/-17)
1 file modified
src/indicator-appmenu.c (+15/-17)
To merge this branch: bzr merge lp:~charlesk/indicator-appmenu/fix-953479
Reviewer Review Type Date Requested Status
Lars Karlitski (community) Approve
Allison Karlitskaya (community) Approve
Review via email: mp+97773@code.launchpad.net

Description of the change

The issue is that we pass the indefinite type ARRAY into g_variant_builder_init() but it's possible that the array will be empty. According to the glib documentation, it's an error to call g_variant_builder_end() "if the builder was created with an indefinite array or maybe type and no children have been added."

h/t desrt

To post a comment you must log in.
Revision history for this message
Allison Karlitskaya (desrt) wrote :

Ya. This looks good. Certainly fixes the bug.

Look just below, though. This same function is leaking 'appkeys'.

If you have some free time, that whole function could be rewritten to look something like so:

GVariantBuilder array;
GHashTable iter;

g_hash_table_iter_init (&iter, iapp->apps);
g_variant_builder_init (&array, G_VARIANT_TYPE ("a(uso)");
while (g_hash_table_iter_next (&iter, &key, &value))
  {
    ...
    g_variant_builder_add (&array, "(uso)", get_xid(), get_address(), get_path());
  }
return g_variant_new ("(a(uso))", &array);

review: Approve
181. By Charles Kerr

better use of GVariant suggested by desrt

Revision history for this message
Charles Kerr (charlesk) wrote :

Ryan, I made most of the modifications you suggested, but am assuming that your last line wasn't literal -- you wouldn't pass a g_variant_builder_init()'ed GVariantBuilder into g_variant_new()'s vararg list, nor return the result immediately?

Revision history for this message
Allison Karlitskaya (desrt) wrote :
review: Needs Fixing
182. By Charles Kerr

further GVariant refinements, h/t desrt again

Revision history for this message
Allison Karlitskaya (desrt) wrote :

Final version looks good.

review: Approve
Revision history for this message
Lars Karlitski (larsu) wrote :

Nothing to add. Great work!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/indicator-appmenu.c'
2--- src/indicator-appmenu.c 2012-03-06 19:34:45 +0000
3+++ src/indicator-appmenu.c 2012-03-16 15:51:24 +0000
4@@ -1259,25 +1259,23 @@
5 return NULL;
6 }
7
8- GVariantBuilder array;
9- g_variant_builder_init (&array, G_VARIANT_TYPE_ARRAY);
10- GList * appkeys = NULL;
11- for (appkeys = g_hash_table_get_keys(iapp->apps); appkeys != NULL; appkeys = g_list_next(appkeys)) {
12- gpointer hash_val = g_hash_table_lookup(iapp->apps, appkeys->data);
13-
14- if (hash_val == NULL) { continue; }
15-
16- GVariantBuilder tuple;
17- g_variant_builder_init(&tuple, G_VARIANT_TYPE_TUPLE);
18- g_variant_builder_add_value(&tuple, g_variant_new_uint32(window_menus_get_xid(WINDOW_MENUS(hash_val))));
19- g_variant_builder_add_value(&tuple, g_variant_new_string(window_menus_get_address(WINDOW_MENUS(hash_val))));
20- g_variant_builder_add_value(&tuple, g_variant_new_object_path(window_menus_get_path(WINDOW_MENUS(hash_val))));
21-
22- g_variant_builder_add_value(&array, g_variant_builder_end(&tuple));
23+ GVariantBuilder builder;
24+ GHashTableIter hash_iter;
25+ gpointer value;
26+
27+ g_variant_builder_init (&builder, G_VARIANT_TYPE("a(uso)"));
28+ g_hash_table_iter_init (&hash_iter, iapp->apps);
29+ while (g_hash_table_iter_next (&hash_iter, NULL, &value)) {
30+ if (value != NULL) {
31+ WindowMenus * wm = WINDOW_MENUS(value);
32+ g_variant_builder_add (&builder, "(uso)",
33+ window_menus_get_xid(wm),
34+ window_menus_get_address(wm),
35+ window_menus_get_path(wm));
36+ }
37 }
38
39- GVariant * varray = g_variant_builder_end(&array);
40- return g_variant_new_tuple(&varray, 1);
41+ return g_variant_new ("(a(uso))", &builder);
42 }
43
44 /* A method has been called from our dbus inteface. Figure out what it

Subscribers

People subscribed via source and target branches