[Vala] using Variant: memory leaks



Hi folks

I am using Vala 0.12
This simple function leaks memory

void leaks()
{
    Variant v = "hello";
    string s = (string)v;
}

Valgrind reveals it:
==17176== LEAK SUMMARY:
==17176==    definitely lost: 6 bytes in 1 blocks

And if you run it in a loop it will eat forever.

I don't know if it is a known bug, if it is fixed in more current
valac, and so on.

Just going more in details, could this help, I will say that the
problem is that that form of casting a Variant to a string will
produce a call to g_variant_dup_string and then the assignment will
produce a call to g_strdup.

Instead, the following form of retrieving a Variant works fine:

void withget()
{
    Variant v = "hello";
    string s;
    v.get("s", out s);
}

HTH,
--Luca



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]