/* note: remove items with matching stream_ids from both lists */
conn_check_prune_stream (agent, stream);
discovery_prune_stream (agent, stream_id);
- refresh_prune_stream_async (agent, stream,
- (NiceTimeoutLockedCallback) on_stream_refreshes_pruned);
-
- agent->pruning_streams = g_slist_prepend (agent->pruning_streams, stream);
/* Remove the stream and signal its removal. */
agent->streams = g_slist_remove (agent->streams, stream);
+ agent->pruning_streams = g_slist_prepend (agent->pruning_streams, stream);
+
+ refresh_prune_stream_async (agent, stream,
+ (NiceTimeoutLockedCallback) on_stream_refreshes_pruned);
if (!agent->streams)
priv_remove_keepalive_timer (agent);
g_slist_free (agent->local_addresses);
agent->local_addresses = NULL;
+ if (agent->refresh_list)
+ g_warning ("Agent %p : We still have alive TURN refreshes. Consider "
+ "using nice_agent_close_async() to prune them before releasing the "
+ "agent.", agent);
+
+ /* We must free refreshes before closing streams because a refresh
+ * callback data may contain a pointer to a stream to be freed, when
+ * previously called in the context of a stream removal, by
+ * refresh_prune_stream_async()
+ */
+ for (i = agent->refresh_list; i;) {
+ GSList *next = i->next;
+ CandidateRefresh *refresh = i->data;
+
+ refresh_free (agent, refresh);
+ i = next;
+ }
+
while (agent->streams) {
NiceStream *s = agent->streams->data;
free_queued_signal (sig);
}
- if (agent->refresh_list)
- g_warning ("Agent %p : We still have alive TURN refreshes. Consider "
- "using nice_agent_close_async() to prune them before releasing the "
- "agent.", agent);
-
- for (i = agent->refresh_list; i;) {
- GSList *next = i->next;
- CandidateRefresh *refresh = i->data;
-
- if (!refresh->disposing)
- refresh_free (agent, refresh);
- i = next;
- }
-
g_free (agent->stun_server_ip);
agent->stun_server_ip = NULL;
static void on_refresh_removed (RefreshPruneAsyncData *data)
{
if (data->items_to_free == 0 || --(data->items_to_free) == 0) {
- GSource *timeout_source = NULL;
- agent_timeout_add_with_context (data->agent, &timeout_source,
- "Async refresh prune", 0, data->cb, data->user_data);
-
- g_source_unref (timeout_source);
+ data->cb (data->agent, data->user_data);
g_free (data);
}
}