[Spice-devel] [spice-gtk v2] wocky: Simplify wocky_http_proxy_connect_finish()
Christophe Fergeau
cfergeau at redhat.com
Thu Aug 4 14:57:11 UTC 2016
Rather than returning the whole ConnectAsyncData struct with
g_task_return_pointer(), we can return only the GIOStream object as this
is what we are interested in.
This has the side-effect of fixing a ConnectAsyncData leak as after
calling g_task_propagate_pointer() the old code had ownership of the
ConnectAsyncData instance but was never freeing it.
The leak is:
==20010== 4,348 (56 direct, 4,292 indirect) bytes in 1 blocks are definitely lost in loss record 20,762 of 20,999
==20010== at 0x4C2DA60: calloc (vg_replace_malloc.c:711)
==20010== by 0xD0F6EB0: g_malloc0 (gmem.c:124)
==20010== by 0x75C0978: wocky_http_proxy_connect_async (wocky-http-proxy.c:359)
==20010== by 0xCB4E22C: g_socket_client_connected_callback (gsocketclient.c:1548)
==20010== by 0xCB57342: g_task_return_now (gtask.c:1107)
==20010== by 0xCB579E5: g_task_return (gtask.c:1165)
==20010== by 0xCB4FB1C: g_socket_connection_connect_callback (gsocketconnection.c:236)
==20010== by 0xCB47160: socket_source_dispatch (gsocket.c:3543)
==20010== by 0xD0F1702: g_main_dispatch (gmain.c:3154)
==20010== by 0xD0F1702: g_main_context_dispatch (gmain.c:3769)
==20010== by 0xD0F1AAF: g_main_context_iterate.isra.29 (gmain.c:3840)
==20010== by 0xD0F1B5B: g_main_context_iteration (gmain.c:3901)
==20010== by 0xCB7D58C: g_application_run (gapplication.c:2381)
==20010== by 0x41571C: main (remote-viewer-main.c:42)
---
src/wocky-http-proxy.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/wocky-http-proxy.c b/src/wocky-http-proxy.c
index f62f1fb..d09cf41 100644
--- a/src/wocky-http-proxy.c
+++ b/src/wocky-http-proxy.c
@@ -454,8 +454,10 @@ reply_read_cb (GObject *source,
return;
}
- g_task_return_pointer (data->task, data, (GDestroyNotify) free_connect_data);
+ g_task_return_pointer (data->task, data->io_stream, (GDestroyNotify) g_object_unref);
+ data->io_stream = NULL;
g_object_unref (data->task);
+ free_connect_data (data);
}
static GIOStream *
@@ -464,9 +466,8 @@ wocky_http_proxy_connect_finish (GProxy *proxy,
GError **error)
{
GTask *task = G_TASK (result);
- ConnectAsyncData *data = g_task_propagate_pointer (task, error);
- return data ? g_object_ref (data->io_stream) : NULL;
+ return g_task_propagate_pointer (task, error);
}
static gboolean
--
2.7.4
More information about the Spice-devel
mailing list