From 1d796cfacd2db2082d83395250565624f1ce5415 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 16 Apr 2014 19:09:06 +0100 Subject: [PATCH] agent: Fix leaks if a component is removed during a recv() call If the error handling block in the middle of the recv() loop is hit, various things were previously leaked (context, cancellable_source) and the return values were potentially incorrect. Fix the break out of the error handling block to clean up correctly. --- agent/agent.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/agent/agent.c b/agent/agent.c index d91b77d..a7a8564 100644 --- a/agent/agent.c +++ b/agent/agent.c @@ -3335,7 +3335,6 @@ nice_agent_recv_messages_blocking_or_nonblocking (NiceAgent *agent, memcpy (&prev_recv_messages_iter, &component->recv_messages_iter, sizeof (NiceInputMessageIter)); - agent_unlock_and_emit (agent); g_main_context_iteration (context, blocking); agent_lock (); @@ -3344,7 +3343,11 @@ nice_agent_recv_messages_blocking_or_nonblocking (NiceAgent *agent, &stream, &component)) { g_set_error (&child_error, G_IO_ERROR, G_IO_ERROR_BROKEN_PIPE, "Component removed during call."); - goto done; + + component = NULL; + error_reported = TRUE; + + goto recv_error; } received_enough = @@ -3360,13 +3363,15 @@ nice_agent_recv_messages_blocking_or_nonblocking (NiceAgent *agent, nice_input_message_iter_get_n_valid_messages ( &component->recv_messages_iter); /* grab before resetting the iter */ - /* Tidy up. */ + component_set_io_callback (component, NULL, NULL, NULL, 0, NULL); + +recv_error: + /* Tidy up. Below this point, @component may be %NULL. */ if (cancellable_source != NULL) { g_source_destroy (cancellable_source); g_source_unref (cancellable_source); } - component_set_io_callback (component, NULL, NULL, NULL, 0, NULL); g_main_context_unref (context); /* Handle errors and cancellations. */ -- 2.7.4