Commit 1d796cfa authored by Philip Withnall's avatar Philip Withnall

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.
parent 5891c956
...@@ -3335,7 +3335,6 @@ nice_agent_recv_messages_blocking_or_nonblocking (NiceAgent *agent, ...@@ -3335,7 +3335,6 @@ nice_agent_recv_messages_blocking_or_nonblocking (NiceAgent *agent,
memcpy (&prev_recv_messages_iter, &component->recv_messages_iter, memcpy (&prev_recv_messages_iter, &component->recv_messages_iter,
sizeof (NiceInputMessageIter)); sizeof (NiceInputMessageIter));
agent_unlock_and_emit (agent); agent_unlock_and_emit (agent);
g_main_context_iteration (context, blocking); g_main_context_iteration (context, blocking);
agent_lock (); agent_lock ();
...@@ -3344,7 +3343,11 @@ nice_agent_recv_messages_blocking_or_nonblocking (NiceAgent *agent, ...@@ -3344,7 +3343,11 @@ nice_agent_recv_messages_blocking_or_nonblocking (NiceAgent *agent,
&stream, &component)) { &stream, &component)) {
g_set_error (&child_error, G_IO_ERROR, G_IO_ERROR_BROKEN_PIPE, g_set_error (&child_error, G_IO_ERROR, G_IO_ERROR_BROKEN_PIPE,
"Component removed during call."); "Component removed during call.");
goto done;
component = NULL;
error_reported = TRUE;
goto recv_error;
} }
received_enough = received_enough =
...@@ -3360,13 +3363,15 @@ nice_agent_recv_messages_blocking_or_nonblocking (NiceAgent *agent, ...@@ -3360,13 +3363,15 @@ nice_agent_recv_messages_blocking_or_nonblocking (NiceAgent *agent,
nice_input_message_iter_get_n_valid_messages ( nice_input_message_iter_get_n_valid_messages (
&component->recv_messages_iter); /* grab before resetting the iter */ &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) { if (cancellable_source != NULL) {
g_source_destroy (cancellable_source); g_source_destroy (cancellable_source);
g_source_unref (cancellable_source); g_source_unref (cancellable_source);
} }
component_set_io_callback (component, NULL, NULL, NULL, 0, NULL);
g_main_context_unref (context); g_main_context_unref (context);
/* Handle errors and cancellations. */ /* Handle errors and cancellations. */
......
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