summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Bruno <lucabru@src.gnome.org>2013-10-26 11:32:23 +0200
committerLuca Bruno <lucabru@src.gnome.org>2013-10-26 11:38:27 +0200
commitb6f7cd6c2aaf5dee64f618a0e06b0d0c157ea352 (patch)
treefe99e285e3864fc68ca088edd96e9d6a5ebdf20f
parentccca45f1aba57d965bb28bfa0e19b1ac2cbc8f97 (diff)
downloadvala-b6f7cd6c2aaf5dee64f618a0e06b0d0c157ea352.tar.gz
Fix memory leak when assigning an owned gvariant to an unowned variable
Fixes bug 710882.
-rw-r--r--codegen/valaccodebasemodule.vala16
1 files changed, 7 insertions, 9 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 5cdd816cd..1d7a5715f 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5491,7 +5491,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public TargetValue transform_value (TargetValue value, DataType? target_type, CodeNode node) {
var type = value.value_type;
var result = ((GLibValue) value).copy ();
- var requires_temp_value = false;
if (type.value_owned
&& type.floating_reference) {
@@ -5547,7 +5546,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
temp_ref_values.insert (0, ((GLibValue) temp_value).copy ());
store_value (temp_value, result);
result.cvalue = get_cvalue_ (temp_value);
- requires_temp_value = false;
}
}
}
@@ -5608,7 +5606,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccode.add_expression (ccall);
result = (GLibValue) temp_value;
- requires_temp_value = false;
} else if (gvariant_boxing) {
// implicit conversion to GVariant
string variant_func = "_variant_new%d".printf (++next_variant_function_id);
@@ -5643,7 +5640,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
cfile.add_function (cfunc);
result.cvalue = ccall;
- requires_temp_value = true;
+ result.value_type.value_owned = true;
+
+ result = (GLibValue) store_temp_value (result, node);
+ if (!target_type.value_owned) {
+ // value leaked
+ temp_ref_values.insert (0, ((GLibValue) result).copy ());
+ }
} else if (boxing) {
// value needs to be boxed
@@ -5651,7 +5654,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (!result.lvalue || !result.value_type.equals (value.value_type)) {
result.cvalue = get_implicit_cast_expression (result.cvalue, value.value_type, result.value_type, node);
result = (GLibValue) store_temp_value (result, node);
- requires_temp_value = false;
}
result.cvalue = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, result.cvalue);
result.lvalue = false;
@@ -5667,10 +5669,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
result.lvalue = result.lvalue && result.cvalue == old_cexpr;
}
- if (requires_temp_value && !(target_type is ArrayType && ((ArrayType) target_type).inline_allocated)) {
- result = (GLibValue) store_temp_value (result, node);
- }
-
if (!gvalue_boxing && !gvariant_boxing && target_type.value_owned && (!type.value_owned || boxing || unboxing) && requires_copy (target_type) && !(type is NullType)) {
// need to copy value
var copy = (GLibValue) copy_value (result, node);