Index: ChangeLog
===================================================================
--- ChangeLog	(revision 2242)
+++ ChangeLog	(working copy)
@@ -1,3 +1,7 @@
+2008-12-30  Philip Van Hoof  <philip@codeminded.be>
+
+	* gobject/valagerrormodule.vala: Newyear present for Jürg, Fix for Bug# 557856
+
 2008-12-26  Jürg Billeter  <j@bitron.ch>
 
 	* gobject/valaccodebasemodule.vala:
Index: gobject/valagerrormodule.vala
===================================================================
--- gobject/valagerrormodule.vala	(revision 2242)
+++ gobject/valagerrormodule.vala	(working copy)
@@ -105,6 +105,12 @@
 			// TODO might be the wrong one when using nested try statements
 
 			var cerror_block = new CCodeBlock ();
+
+			// free local variables
+			var free_frag = new CCodeFragment ();
+			append_error_free (current_symbol, free_frag, current_try);
+			cerror_block.add_statement (free_frag);
+
 			foreach (CatchClause clause in current_try.get_catch_clauses ()) {
 				// go to catch clause if error domain matches
 				var cgoto_stmt = new CCodeGotoStatement (clause.clabel_name);
@@ -157,6 +163,12 @@
 			// unhandled error
 
 			var cerror_block = new CCodeBlock ();
+
+			// free local variables
+			var free_frag = new CCodeFragment ();
+			append_local_free (current_symbol, free_frag, false);
+			cerror_block.add_statement (free_frag);
+
 			// print critical message
 			cerror_block.add_statement (cprint_frag);
 
Index: gobject/valaccodebasemodule.vala
===================================================================
--- gobject/valaccodebasemodule.vala	(revision 2242)
+++ gobject/valaccodebasemodule.vala	(working copy)
@@ -2055,6 +2055,28 @@
 		}
 	}
 
+	public void append_error_free (Symbol sym, CCodeFragment cfrag, TryStatement current_try) {
+		var b = (Block) sym;
+
+		var local_vars = b.get_local_variables ();
+		foreach (LocalVariable local in local_vars) {
+			if (local.active && !local.floating && 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 (sym == current_try.body)
+			return;
+
+		if (sym.parent_symbol is Block) {
+			append_error_free (sym.parent_symbol, cfrag, current_try);
+		} else if (sym.parent_symbol is Method) {
+			append_param_free ((Method) sym.parent_symbol, cfrag);
+		}
+	}
+
 	private void append_param_free (Method m, CCodeFragment cfrag) {
 		foreach (FormalParameter param in m.get_parameters ()) {
 			if (requires_destroy (param.parameter_type) && param.direction == ParameterDirection.IN) {
