From: Jürg Billeter Date: Thu, 13 Jan 2011 12:54:19 +0000 (+0100) Subject: codegen: Limit scope of locals freed on errors thrown from catch clauses X-Git-Tag: 0.11.4~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=359ea7585ac30d4f074e59bdcd324f81f974acbe;p=thirdparty%2Fvala.git codegen: Limit scope of locals freed on errors thrown from catch clauses This fixes double unref of closures. --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index c13a541af..ba0cac133 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -31,6 +31,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { public Symbol? current_symbol; public ArrayList symbol_stack = new ArrayList (); public TryStatement current_try; + public CatchClause current_catch; public CCodeFunction ccode; public ArrayList ccode_stack = new ArrayList (); public ArrayList temp_ref_vars = new ArrayList (); @@ -69,6 +70,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { set { emit_context.current_try = value; } } + public CatchClause current_catch { + get { return emit_context.current_catch; } + set { emit_context.current_catch = value; } + } + public TypeSymbol? current_type_symbol { get { var sym = current_symbol; diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala index 10352f7f3..4d464ef98 100644 --- a/codegen/valagerrormodule.vala +++ b/codegen/valagerrormodule.vala @@ -179,7 +179,11 @@ public class Vala.GErrorModule : CCodeDelegateModule { // surrounding try found // free local variables - append_local_free (current_symbol, false, current_try); + if (is_in_catch) { + append_local_free (current_symbol, false, current_catch); + } else { + append_local_free (current_symbol, false, current_try); + } var error_types = new ArrayList (); foreach (DataType node_error_type in node.get_error_types ()) { @@ -295,6 +299,7 @@ public class Vala.GErrorModule : CCodeDelegateModule { var old_try = current_try; var old_try_id = current_try_id; var old_is_in_catch = is_in_catch; + var old_catch = current_catch; current_try = stmt; current_try_id = this_try_id; is_in_catch = true; @@ -308,6 +313,7 @@ public class Vala.GErrorModule : CCodeDelegateModule { is_in_catch = true; foreach (CatchClause clause in stmt.get_catch_clauses ()) { + current_catch = clause; ccode.add_goto ("__finally%d".printf (this_try_id)); clause.emit (this); } @@ -315,6 +321,7 @@ public class Vala.GErrorModule : CCodeDelegateModule { current_try = old_try; current_try_id = old_try_id; is_in_catch = old_is_in_catch; + current_catch = old_catch; ccode.add_label ("__finally%d".printf (this_try_id)); if (stmt.finally_body != null) {