When running my application under Valgrind and I am trying to track down a 449K byte leak related to a GVariant. The code in question looks like this:
GVariant *variant1, *variant2, *elem;
GVariantIter iter;
variant1 = g_variant_parse(G_VARIANT_TYPE("(ttv)"), data, len, NULL, &error);
if (!variant1)
error();
g_variant_get(variant1, "(ttv)", &v, &s, &variant2);
g_variant_iter_init(&iter, variant2);
while ((elem = g_variant_iter_next_value(&iter)) {
parse_iter_element(elem);
g_variant_unref(elem);
}
g_variant_unref(variant2);
g_variant_unref(variant1);
As far as I can tell, all of the variants are being unref’ed properly. elem
is a complex GVariant, containing other variants but those seemed to also being unref’ed.
Valgrind is showing that the leak is in the call path starting at the g_variant_parse
call. I am not entirely clear how the reference counting works in the above code.