[vala] D-Bus: Fix memory leak in error handling in async GDBus servers



commit bbf3eb8aad28963a5097f3024b844c8709f38d86
Author: Jürg Billeter <j bitron ch>
Date:   Thu Jan 13 15:36:35 2011 +0100

    D-Bus: Fix memory leak in error handling in async GDBus servers

 codegen/valagdbusservermodule.vala |   29 ++++++++++++-----------------
 1 files changed, 12 insertions(+), 17 deletions(-)
---
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index 0e1acea..b06226b 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -208,11 +208,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
 		if (m.coroutine && !ready) {
 			ccall.add_argument (new CCodeCastExpression (new CCodeIdentifier (wrapper_name + "_ready"), "GAsyncReadyCallback"));
-
-			var ref_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_ref"));
-			ref_call.add_argument (new CCodeIdentifier ("invocation"));
-
-			ccall.add_argument (ref_call);
+			ccall.add_argument (new CCodeIdentifier ("invocation"));
 		}
 
 		if (!m.coroutine || ready) {
@@ -231,12 +227,8 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			if (m.get_error_types ().size > 0) {
 				ccode.open_if (new CCodeIdentifier ("error"));
 
-				// g_dbus_method_invocation_return_gerror consumes reference
-				var ref_invocation = new CCodeFunctionCall (new CCodeIdentifier ("g_object_ref"));
-				ref_invocation.add_argument (new CCodeIdentifier ("invocation"));
-
 				var return_error = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_method_invocation_return_gerror"));
-				return_error.add_argument (ref_invocation);
+				return_error.add_argument (new CCodeIdentifier ("invocation"));
 				return_error.add_argument (new CCodeIdentifier ("error"));
 				ccode.add_expression (return_error);
 
@@ -393,13 +385,12 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			return_value.add_argument (new CCodeConstant ("NULL"));
 			ccode.add_expression (return_value);
 
-			if (ready) {
-				var unref_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
-				unref_call.add_argument (new CCodeIdentifier ("invocation"));
-				ccode.add_expression (unref_call);
-			}
-
+			// free invocation like g_dbus_method_invocation_return_*
 			var unref_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
+			unref_call.add_argument (new CCodeIdentifier ("invocation"));
+			ccode.add_expression (unref_call);
+
+			unref_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
 			unref_call.add_argument (new CCodeIdentifier ("_reply_message"));
 			ccode.add_expression (unref_call);
 		}
@@ -669,13 +660,17 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 		}
 
 		if (!first) {
-			ccode.close ();
+			ccode.add_else ();
 		}
 
 		var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
 		ccall.add_argument (new CCodeIdentifier ("invocation"));
 		ccode.add_expression (ccall);
 
+		if (!first) {
+			ccode.close ();
+		}
+
 		pop_function ();
 
 		cfile.add_function_declaration (cfunc);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]