[vala] codegen: Limit scope of locals freed on errors thrown from catch clauses
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Limit scope of locals freed on errors thrown from catch clauses
- Date: Thu, 13 Jan 2011 14:43:05 +0000 (UTC)
commit 359ea7585ac30d4f074e59bdcd324f81f974acbe
Author: Jürg Billeter <j bitron ch>
Date: Thu Jan 13 13:54:19 2011 +0100
codegen: Limit scope of locals freed on errors thrown from catch clauses
This fixes double unref of closures.
codegen/valaccodebasemodule.vala | 6 ++++++
codegen/valagerrormodule.vala | 9 ++++++++-
2 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index c13a541..ba0cac1 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> symbol_stack = new ArrayList<Symbol> ();
public TryStatement current_try;
+ public CatchClause current_catch;
public CCodeFunction ccode;
public ArrayList<CCodeFunction> ccode_stack = new ArrayList<CCodeFunction> ();
public ArrayList<LocalVariable> temp_ref_vars = new ArrayList<LocalVariable> ();
@@ -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 10352f7..4d464ef 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<DataType> ();
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) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]