After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 472904 - Massive memory leak in property handling
Massive memory leak in property handling
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
0.1.x
Other All
: Normal blocker
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2007-09-02 18:32 UTC by Mathias Hasselmann (IRC: tbf)
Modified: 2007-09-20 21:30 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Mathias Hasselmann (IRC: tbf) 2007-09-02 18:32:34 UTC
There is a massive memory leak in property handling:

    public interface SpellCheckSection : GLib.Object {
        public abstract string! text { get; construct; }
        public abstract int length { get; construct; }
        public abstract string! language { get; set; }
    }

SpellCheckSection.text.get () is compiled to:

char* gtk_spell_check_section_get_text (GtkSpellCheckSection* self)
{
	char* value;
	g_object_get (G_OBJECT (self), "text", &value, NULL);
	return value;
}

So with each reading of that property new memory is allocated. Unfortunatly vala never releases the string returned by gtk_spell_check_section_get_text.

Possible solutions for the problem:

 a) Directly invoke g_object_get and free the temp variable when leaving the calling function. Safe but slow.

 b) Call the virtual property accessor which looks correct, expect for the missing const modifier:

static char* gtk_spell_check_default_section_real_get_text (GtkSpellCheckDefaultSection* self)
{
	g_return_val_if_fail (GTK_IS_SPELL_CHECK_DEFAULT_SECTION (self), NULL);
	return self->priv->_text;
}
Comment 1 Mathias Hasselmann (IRC: tbf) 2007-09-02 20:15:25 UTC
Potential regression test for that issue:

using GLib;

interface Maman.Foo : GLib.Object {
	public abstract string! text { get; }
}

class Maman.Bar : GLib.Object, Maman.Foo {
	public virtual string! text {
		get { return "The Maman Bar"; }
	}

	static void main () {
		var bar = new Bar ();
		string text = bar.text;
	}
}
Comment 2 Jürg Billeter 2007-09-08 21:11:59 UTC
Confirming.
Comment 3 Raffaele Sandrini 2007-09-20 21:30:17 UTC
Fixed in SVN r625.

We enforce you now to transfer ownership with properties using non reference counting reference types. With reference counting types we use a hack in the getter decrementing the reference count before returning it which somehow simulates a weak reference.

So your test needs to be rewritten into:
using GLib;

interface Maman.Foo : GLib.Object {
        public abstract string!# text { get; }
}

class Maman.Bar : GLib.Object, Maman.Foo {
        public virtual string!# text {
                get { return "The Maman Bar"; }
        }

        static void main () {
                var bar = new Bar ();
                string text = bar.text;
        }
}