[vala/staging] gdbus: Fix memleak using g_task_propagate_pointer



commit fc8a6ac1de1e162bf817fee704f15e38383b755e
Author: mrmacete <mrmacete protonmail ch>
Date:   Tue Feb 21 15:34:43 2017 +0100

    gdbus: Fix memleak using g_task_propagate_pointer
    
    https://bugzilla.gnome.org/show_bug.cgi?id=778993

 codegen/valagdbusclientmodule.vala |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index ac45b58..a0151f6 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -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 *"));


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