]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
GVariant: Fix memory leak when boxing and unboxing variants
authorJürg Billeter <j@bitron.ch>
Sat, 2 Jun 2012 15:03:40 +0000 (17:03 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 23 Jun 2012 15:27:50 +0000 (17:27 +0200)
Fixes bug 674201.

codegen/valaccodebasemodule.vala
vala/valacastexpression.vala

index 55af6c51e028f11bfc5948baa79ab3830eca6e7f..13a144696b7950b8931f16f91794d5101b04ba9f 100644 (file)
@@ -5285,7 +5285,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                        && type.data_type != gvariant_type);
 
                if (type.value_owned
-                   && (target_type == null || !target_type.value_owned || boxing || unboxing)
+                   && (target_type == null || !target_type.value_owned || boxing || unboxing || gvariant_boxing)
                    && !gvalue_boxing /* gvalue can assume ownership of value, no need to free it */) {
                        // value leaked, destroy it
                        if (target_type is PointerType) {
index 40ed1ce3ffe20fcaa67bbc95cf02e885514d841c..c7a72b6f254e20a7260317c2d1d7522f12093fe5 100644 (file)
@@ -152,11 +152,20 @@ public class Vala.CastExpression : Expression {
                        value_type.nullable = true;
                }
 
+               if (is_gvariant (context, inner.value_type) && !is_gvariant (context, value_type)) {
+                       // GVariant unboxing returns owned value
+                       value_type.value_owned = true;
+               }
+
                inner.target_type = inner.value_type.copy ();
 
                return !error;
        }
 
+       bool is_gvariant (CodeContext context, DataType type) {
+               return type.data_type != null && type.data_type.is_subtype_of (context.analyzer.gvariant_type.data_type);
+       }
+
        public override void emit (CodeGenerator codegen) {
                inner.emit (codegen);