summaryrefslogtreecommitdiff
path: root/agent
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2014-09-25 09:21:44 +0100
committerPhilip Withnall <philip.withnall@collabora.co.uk>2014-09-25 09:54:19 +0100
commita8ec764adb5b8b65f5a6eaae1ab4c87f4341d802 (patch)
tree78b96fbfb67aefdc71eff362e156ff45b907e80b /agent
parent3516890dbe7873fde797361640abc5be05fd0089 (diff)
agent: Fix a leak of a GCancellable and its GSource
The GSource holds a reference to the GCancellable, so needs to be explicitly removed from the GMainContext when it’s finised with.
Diffstat (limited to 'agent')
-rw-r--r--agent/component.c14
-rw-r--r--agent/component.h1
2 files changed, 10 insertions, 5 deletions
diff --git a/agent/component.c b/agent/component.c
index dbf8fb4..064a6d5 100644
--- a/agent/component.c
+++ b/agent/component.c
@@ -120,7 +120,6 @@ Component *
component_new (guint id, NiceAgent *agent, Stream *stream)
{
Component *component;
- GSource *src;
component = g_slice_new0 (Component);
component->id = id;
@@ -138,10 +137,10 @@ component_new (guint id, NiceAgent *agent, Stream *stream)
component->own_ctx = g_main_context_new ();
component->stop_cancellable = g_cancellable_new ();
- src = g_cancellable_source_new (component->stop_cancellable);
- g_source_set_dummy_callback (src);
- g_source_attach (src, component->own_ctx);
- g_source_unref (src);
+ component->stop_cancellable_source =
+ g_cancellable_source_new (component->stop_cancellable);
+ g_source_set_dummy_callback (component->stop_cancellable_source);
+ g_source_attach (component->stop_cancellable_source, component->own_ctx);
component->ctx = g_main_context_ref (component->own_ctx);
/* Start off with a fresh main context and all I/O paused. This
@@ -285,6 +284,11 @@ component_free (Component *cmp)
g_clear_object (&cmp->iostream);
g_mutex_clear (&cmp->io_mutex);
+ if (cmp->stop_cancellable_source != NULL) {
+ g_source_destroy (cmp->stop_cancellable_source);
+ g_source_unref (cmp->stop_cancellable_source);
+ }
+
if (cmp->ctx != NULL) {
g_main_context_unref (cmp->ctx);
cmp->ctx = NULL;
diff --git a/agent/component.h b/agent/component.h
index 9bcff09..7ded710 100644
--- a/agent/component.h
+++ b/agent/component.h
@@ -193,6 +193,7 @@ struct _Component
GCancellable *stop_cancellable;
+ GSource *stop_cancellable_source; /* owned */
PseudoTcpSocket *tcp;
GSource* tcp_clock;