]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Fix leak when casting from variant to another type
authorLuca Bruno <lucabru@src.gnome.org>
Mon, 15 Aug 2011 18:30:54 +0000 (20:30 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Mon, 15 Aug 2011 18:35:01 +0000 (20:35 +0200)
Fixes bug 656398.

codegen/valaccodebasemodule.vala

index e0011e7bdadab9240c9552b75013eb7927a5b2b6..2a2ee263910a3406d02dc650a06613e09524aeb4 100644 (file)
@@ -4512,8 +4512,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                string variant_func = "_variant_get%d".printf (++next_variant_function_id);
 
+               var variant = value;
+               if (value.value_type.value_owned) {
+                       // value leaked, destroy it
+                       var temp_value = store_temp_value (value, node);
+                       temp_ref_values.insert (0, ((GLibValue) temp_value).copy ());
+                       variant = temp_value;
+               }
+
                var ccall = new CCodeFunctionCall (new CCodeIdentifier (variant_func));
-               ccall.add_argument (get_cvalue_ (value));
+               ccall.add_argument (get_cvalue_ (variant));
 
                var result = create_temp_value (to, false, node);