GNOME Bugzilla – Bug 778993
GDBusClientModule memory leak in generated code
Last modified: 2017-02-21 15:24:40 UTC
Created attachment 346294 [details] [review] Fix memleak in GDBusClientModule generated code In the code generated by GDBusClientModule,when calling g_dbus_connection_send_message_with_reply_finish, the result of g_task_propagate_pointer is leaked, since the called function doesn't take ownership of it. The proposed solution is to keep a reference to the g_task_propagate_pointer return value, and call g_object_unref after passing it down to the function which uses it.
Review of attachment 346294 [details] [review]: Good catch :). g_task_propagate_pointer() indeed transfers ownership of the returned pointer to the caller, so it must be freed here. ::: codegen/valagdbusclientmodule.vala @@ +742,3 @@ ccode.add_assignment (new CCodeIdentifier ("_reply_message"), ccall); + + var unref_inner_res = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref")); It took me a while to convince myself that the returned object can't be NULL here. given g_task_propagate_pointer() can possibly return NULL according to docs, I think it'd still be clearer here if this were NULL-safe.
Created attachment 346358 [details] [review] Updated patch with comment Updated the patch with a comment on NULL-safety
Created attachment 346359 [details] [review] Updated patch with comment (again) This one is correct (earlier i accidentally re-uploaded the old one)
Please attach patches created with "git format-patch" for proper credits.
Created attachment 346363 [details] Patch generated with git format-patch
Created attachment 346364 [details] [review] Patch generated with git format-patch
commit fc8a6ac1de1e162bf817fee704f15e38383b755e Author: mrmacete <mrmacete@protonmail.ch> Date: Tue Feb 21 15:34:43 2017 +0100 gdbus: Fix memleak using g_task_propagate_pointer