[vala] codegen: Fix memory leak introduced by fe9beb82b6809



commit 550b1078962eea5e5395078e61ae8344b1066bf9
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat Jan 4 21:03:51 2014 +0100

    codegen: Fix memory leak introduced by fe9beb82b6809

 codegen/valaccodebasemodule.vala |    2 ++
 tests/methods/closures.vala      |   18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index b3680d5..4f049c1 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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);
diff --git a/tests/methods/closures.vala b/tests/methods/closures.vala
index d2be8e0..00c3ce8 100644
--- a/tests/methods/closures.vala
+++ b/tests/methods/closures.vala
@@ -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);
 }
 


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