G_variant_parse() and GVariant reference counting question

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)
g_variant_get(variant1, "(ttv)", &v, &s, &variant2);
g_variant_iter_init(&iter, variant2);
while ((elem = g_variant_iter_next_value(&iter)) {

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.

There are a lot of GVariant code examples at


that might be helpful. Have you taken a look at these?


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.