]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Fix memory leak introduced by fe9beb82b6809
authorLuca Bruno <lucabru@src.gnome.org>
Sat, 4 Jan 2014 20:03:51 +0000 (21:03 +0100)
committerLuca Bruno <lucabru@src.gnome.org>
Sat, 4 Jan 2014 20:03:51 +0000 (21:03 +0100)
codegen/valaccodebasemodule.vala
tests/methods/closures.vala

index b3680d574435ffddfdd3c4179fd8ac53615446ba..4f049c1e67eea00e1067a4caad907f4f9991a7e1 100644 (file)
@@ -2117,6 +2117,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        } else {
                                var this_type = get_this_type ();
                                if (this_type != null) {
+                                       this_type = this_type.copy ();
+                                       this_type.value_owned = true;
                                        if (this_type.is_disposable () && !is_in_destructor ()) {
                                                // reference count for self is not increased in finalizers
                                                var this_value = new GLibValue (get_data_type_for_symbol (current_type_symbol), new CCodeIdentifier ("self"), true);
index d2be8e0d9af5b7bea0c478785f0dcbef95a7457a..00c3ce8087de29038fd57f0ece7fbc5381dfa733 100644 (file)
@@ -1,5 +1,17 @@
 delegate int Func ();
 
+class Foo : Object {
+       public void bar (MainLoop loop) {
+               Object o = new Object ();
+               SourceFunc f = () => {
+                       o = null;
+                       loop.quit ();
+                       return false;
+               };
+               GLib.Idle.add ((owned) f);
+       }
+}
+
 [CCode (has_target = false)]
 delegate void NoTargetFunc ();
 
@@ -19,5 +31,11 @@ void B ([CCode (array_length = false, array_null_terminated = true)] int[] array
 void main () {
        int result = A (10, () => 1, () => -1, () => -1, () => 1, () => 0);
        assert (result == -67);
+
+       var foo = new Foo ();
+       var loop = new MainLoop ();
+       foo.bar (loop);
+       loop.run ();
+       assert (foo.ref_count == 1);
 }