[vala] D-Bus: Fix memory leaks when handling signals in static clients
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] D-Bus: Fix memory leaks when handling signals in static clients
- Date: Wed, 10 Feb 2010 12:28:47 +0000 (UTC)
commit 0917027522a311cc1868cb028bc5ac7fd2b8b2c5
Author: Jürg Billeter <j bitron ch>
Date: Wed Feb 10 13:28:09 2010 +0100
D-Bus: Fix memory leaks when handling signals in static clients
codegen/valadbusclientmodule.vala | 17 ++++++++++++++++-
1 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valadbusclientmodule.vala b/codegen/valadbusclientmodule.vala
index 5266173..023abde 100644
--- a/codegen/valadbusclientmodule.vala
+++ b/codegen/valadbusclientmodule.vala
@@ -1326,6 +1326,7 @@ internal class Vala.DBusClientModule : DBusModule {
var block = new CCodeBlock ();
var prefragment = new CCodeFragment ();
+ var postfragment = new CCodeFragment ();
cdecl = new CCodeDeclaration ("DBusMessageIter");
cdecl.add_declarator (new CCodeVariableDeclarator ("iter"));
@@ -1354,7 +1355,10 @@ internal class Vala.DBusClientModule : DBusModule {
string type_signature = "";
foreach (FormalParameter param in sig.get_parameters ()) {
- cdecl = new CCodeDeclaration (param.parameter_type.get_cname ());
+ var owned_type = param.parameter_type.copy ();
+ owned_type.value_owned = true;
+
+ cdecl = new CCodeDeclaration (owned_type.get_cname ());
cdecl.add_declarator (new CCodeVariableDeclarator.zero (param.name, default_value_for_type (param.parameter_type, true)));
prefragment.append (cdecl);
@@ -1388,12 +1392,23 @@ internal class Vala.DBusClientModule : DBusModule {
var target = new CCodeIdentifier (param.name);
var expr = read_expression (prefragment, param.parameter_type, new CCodeIdentifier ("iter"), target);
prefragment.append (new CCodeExpressionStatement (new CCodeAssignment (target, expr)));
+
+ if (requires_destroy (owned_type)) {
+ // keep local alive (symbol_reference is weak)
+ var local = new LocalVariable (owned_type, param.name);
+ var ma = new MemberAccess.simple (param.name);
+ ma.symbol_reference = local;
+ var stmt = new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (param.name), owned_type, ma));
+ postfragment.append (stmt);
+ }
}
signature_check.add_argument (new CCodeConstant ("\"%s\"".printf (type_signature)));
block.add_statement (new CCodeExpressionStatement (ccall));
+ block.add_statement (postfragment);
+
cdecl = new CCodeDeclaration ("DBusMessage*");
cdecl.add_declarator (new CCodeVariableDeclarator ("reply"));
block.add_statement (cdecl);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]