[vala] codegen: Fix leak when casting from variant to another type



commit 3390ee1bfc49a29af86c7125fd601d3f08916868
Author: Luca Bruno <lucabru src gnome org>
Date:   Mon Aug 15 20:30:54 2011 +0200

    codegen: Fix leak when casting from variant to another type
    
    Fixes bug 656398.

 codegen/valaccodebasemodule.vala |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index e0011e7..2a2ee26 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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);
 



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