[vala] Fix memory management of captured variables in error handlers



commit ab6c34b398cb5f4cf177ffc48afa82ed9dc2ff4a
Author: Jürg Billeter <j bitron ch>
Date:   Wed Mar 3 14:10:35 2010 +0100

    Fix memory management of captured variables in error handlers
    
    Fixes bug 611624.

 codegen/valaccodebasemodule.vala |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 287e494..52b0eef 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3163,13 +3163,21 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
 		var local_vars = b.get_local_variables ();
 		foreach (LocalVariable local in local_vars) {
-			if (local.active && !local.floating && requires_destroy (local.variable_type)) {
+			if (local.active && !local.floating && !local.captured && requires_destroy (local.variable_type)) {
 				var ma = new MemberAccess.simple (local.name);
 				ma.symbol_reference = local;
 				cfrag.append (new CCodeExpressionStatement (get_unref_expression (get_variable_cexpression (local.name), local.variable_type, ma)));
 			}
 		}
 
+		if (b.captured) {
+			int block_id = get_block_id (b);
+
+			var data_unref = new CCodeFunctionCall (new CCodeIdentifier ("block%d_data_unref".printf (block_id)));
+			data_unref.add_argument (get_variable_cexpression ("_data%d_".printf (block_id)));
+			cfrag.append (new CCodeExpressionStatement (data_unref));
+		}
+
 		if (sym == current_try.body) {
 			return;
 		}



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