Commit a8ec764a authored by Philip Withnall's avatar Philip Withnall

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.
parent 3516890d
...@@ -120,7 +120,6 @@ Component * ...@@ -120,7 +120,6 @@ Component *
component_new (guint id, NiceAgent *agent, Stream *stream) component_new (guint id, NiceAgent *agent, Stream *stream)
{ {
Component *component; Component *component;
GSource *src;
component = g_slice_new0 (Component); component = g_slice_new0 (Component);
component->id = id; component->id = id;
...@@ -138,10 +137,10 @@ component_new (guint id, NiceAgent *agent, Stream *stream) ...@@ -138,10 +137,10 @@ component_new (guint id, NiceAgent *agent, Stream *stream)
component->own_ctx = g_main_context_new (); component->own_ctx = g_main_context_new ();
component->stop_cancellable = g_cancellable_new (); component->stop_cancellable = g_cancellable_new ();
src = g_cancellable_source_new (component->stop_cancellable); component->stop_cancellable_source =
g_source_set_dummy_callback (src); g_cancellable_source_new (component->stop_cancellable);
g_source_attach (src, component->own_ctx); g_source_set_dummy_callback (component->stop_cancellable_source);
g_source_unref (src); g_source_attach (component->stop_cancellable_source, component->own_ctx);
component->ctx = g_main_context_ref (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 /* Start off with a fresh main context and all I/O paused. This
...@@ -285,6 +284,11 @@ component_free (Component *cmp) ...@@ -285,6 +284,11 @@ component_free (Component *cmp)
g_clear_object (&cmp->iostream); g_clear_object (&cmp->iostream);
g_mutex_clear (&cmp->io_mutex); 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) { if (cmp->ctx != NULL) {
g_main_context_unref (cmp->ctx); g_main_context_unref (cmp->ctx);
cmp->ctx = NULL; cmp->ctx = NULL;
......
...@@ -193,6 +193,7 @@ struct _Component ...@@ -193,6 +193,7 @@ struct _Component
GCancellable *stop_cancellable; GCancellable *stop_cancellable;
GSource *stop_cancellable_source; /* owned */
PseudoTcpSocket *tcp; PseudoTcpSocket *tcp;
GSource* tcp_clock; GSource* tcp_clock;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment