Hello,
I'm using glibd in a GDBus server of mine and overall I really enjoy using it. However, I started profiling the thing with Valgrind and noticed some memory leaks, especially around using VariantBuilder
. So I thought it might be a good idea to use the stack allocated VariantBuilder
s and explicitly call .clear
on those to avoid leaking memory, but the following piece of code SIGSEGVs for me:
import glib.VariantBuilder;
import glib.VariantType;
void main() {
VariantBuilder builder;
builder.init(new VariantType("a(s)"));
}
I'm not exactly sure what I'm doing wrong, since this (seemingly) equivalent piece of code written with the C API seems to work:
import glib.c.types;
import glib.c.functions;
import glib.VariantType;
void main() {
GVariantBuilder builder;
g_variant_builder_init(&builder, new VariantType("a(s)").getVariantTypeStruct(true));
}
FWIW in my actual code I did something like this:
Variant getAll()
{
auto builder = new VariantBuilder(new VariantType("a{sv}"));
builder.open(new VariantType("{sv}"));
builder.addValue(new Variant("allowUntrustedRepos"));
builder.addValue(new Variant(new Variant(this.allowUntrustedRepositories)));
builder.close();
builder.open(new VariantType("{sv}"));
builder.addValue(new Variant("root"));
builder.addValue(new Variant(new Variant(this.root)));
builder.close();
return builder.end();
}
And apparently that leaks memory - or was that just Valgrind not liking what the GC did?