vala r2251 - in trunk: . gobject
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r2251 - in trunk: . gobject
- Date: Thu, 1 Jan 2009 19:03:49 +0000 (UTC)
Author: juergbi
Date: Thu Jan 1 19:03:49 2009
New Revision: 2251
URL: http://svn.gnome.org/viewvc/vala?rev=2251&view=rev
Log:
2009-01-01 JÃrg Billeter <j bitron ch>
* gobject/valaccodebasemodule.vala:
* gobject/valagerrormodule.vala:
Fix memory leaks when handling errors, patch by Philip Van Hoof,
fixes bug 557856
Modified:
trunk/ChangeLog
trunk/gobject/valaccodebasemodule.vala
trunk/gobject/valagerrormodule.vala
Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala (original)
+++ trunk/gobject/valaccodebasemodule.vala Thu Jan 1 19:03:49 2009
@@ -2055,6 +2055,29 @@
}
}
+ 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) {
Modified: trunk/gobject/valagerrormodule.vala
==============================================================================
--- trunk/gobject/valagerrormodule.vala (original)
+++ trunk/gobject/valagerrormodule.vala Thu Jan 1 19:03:49 2009
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]