memory leak in menuitem_property_idle
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
DBus Menu |
New
|
Undecided
|
Unassigned | ||
libdbusmenu (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
This bug discusses the segment of code beginning at line 955 of server.c
http://
The megadata variants are created in two possible ways. One involves g_variant_
This strategy is incorrect. As documented below, g_variant_builder returns a floating reference, whereas g_variant_parse returns a regular reference. Actually, the documentation for the latter is not explicit, but it appears that it what it indicates.
http://
There are at least two problems here.
1. g_variant_unref does not work for floating references, so it cannot free variants created by g_variant_
2. the g_variant_new_tuple constructor does not take ownership of its arguments if they are standard references
The implementation needs to ensure that both of the megadata variants are properly freed in all code paths. There are likely many ways to due this, and I suspect that irrespective of whatever I suggest, you will probably do something slightly different. In essence, there are two ways each can be created, and two ways they can be destroyed, for a total of 4 possibilities. The code needs to account for them all.
Below are valgrind logs confirming the problem.
==10301== 1,480 bytes in 37 blocks are definitely lost in loss record 9,062 of 9,326
==10301== at 0x4C28FAC: malloc (vg_replace_
==10301== by 0x8F62A62: g_malloc (gmem.c:164)
==10301== by 0x8F79666: g_slice_alloc (gslice.c:842)
==10301== by 0x8F97A09: g_variant_alloc (gvariant-
==10301== by 0x8F97B0C: g_variant_
==10301== by 0x8F9532D: g_variant_
==10301== by 0x8F98E67: array_get_value (gvariant-
==10301== by 0x8F98699: maybe_wrapper (gvariant-
==10301== by 0x8F9B5FF: g_variant_parse (gvariant-
==10301== by 0x5046D8E: menuitem_
==10301== by 0x8F5BBCC: g_main_
==10301== by 0x8F5C3A7: g_main_
==10301== by 0x8F5C9F1: g_main_loop_run (gmain.c:3299)
==10301== by 0x416D77: main (main.c:101)
==10301== 480 bytes in 12 blocks are definitely lost in loss record 8,789 of 9,326
==10301== at 0x4C28FAC: malloc (vg_replace_
==10301== by 0x8F62A62: g_malloc (gmem.c:164)
==10301== by 0x8F79666: g_slice_alloc (gslice.c:842)
==10301== by 0x8F97A09: g_variant_alloc (gvariant-
==10301== by 0x8F97B0C: g_variant_
==10301== by 0x8F9532D: g_variant_
==10301== by 0x8F98E67: array_get_value (gvariant-
==10301== by 0x8F98699: maybe_wrapper (gvariant-
==10301== by 0x8F9B5FF: g_variant_parse (gvariant-
==10301== by 0x5046E13: menuitem_
==10301== by 0x8F5BBCC: g_main_
==10301== by 0x8F5C3A7: g_main_
==10301== by 0x8F5C9F1: g_main_loop_run (gmain.c:3299)
==10301== by 0x416D77: main (main.c:101)
In the above post I expressed some doubt as to whether g_variant_parse returns a regular reference or floating reference. Indeed the documentation is not completely explicit on this point.
However, reading the source makes it clear that it is a non-floating reference, as I have claimed.
http:// bazaar. launchpad. net/~ubuntu- branches/ ubuntu/ oneiric/ glib2.0/ oneiric/ view/head: /glib/gvariant- parser. c
Note the call to g_variant_ref_sink.