]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
gdbus: Fix memleak using g_task_propagate_pointer
authormrmacete <mrmacete@protonmail.ch>
Tue, 21 Feb 2017 14:34:43 +0000 (15:34 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 21 Feb 2017 14:52:12 +0000 (15:52 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=778993

codegen/valagdbusclientmodule.vala

index ac45b58cd8cab01d9a8dae0c33d6828c427a06ca..a0151f6e306cb35520131c3db77f0e5791401b82 100644 (file)
@@ -729,13 +729,21 @@ public class Vala.GDBusClientModule : GDBusModule {
 
                        // unwrap async result
                        if (context.require_glib_version (2, 36)) {
+                               ccode.add_declaration ("GAsyncResult", new CCodeVariableDeclarator ("*_inner_res"));
+
                                var inner_res = new CCodeFunctionCall (new CCodeIdentifier ("g_task_propagate_pointer"));
                                inner_res.add_argument (new CCodeCastExpression (new CCodeIdentifier ("_res_"), "GTask *"));
                                inner_res.add_argument (new CCodeConstant ("NULL"));
-                               ccall.add_argument (inner_res);
+                               ccode.add_assignment (new CCodeIdentifier ("_inner_res"), inner_res);
 
+                               ccall.add_argument (new CCodeIdentifier ("_inner_res"));
                                ccall.add_argument (new CCodeConstant ("error"));
                                ccode.add_assignment (new CCodeIdentifier ("_reply_message"), ccall);
+
+                               // _inner_res is guaranteed to be non-NULL, so just unref it
+                               var unref_inner_res = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
+                               unref_inner_res.add_argument (new CCodeIdentifier ("_inner_res"));
+                               ccode.add_expression (unref_inner_res);
                        } else {
                                var inner_res = new CCodeFunctionCall (new CCodeIdentifier ("g_simple_async_result_get_op_res_gpointer"));
                                inner_res.add_argument (new CCodeCastExpression (new CCodeIdentifier ("_res_"), "GSimpleAsyncResult *"));