Commit 571d833b authored by Youness Alaoui's avatar Youness Alaoui

Hopefully fix a race condition when disposing of the turn socket and the timer...

Hopefully fix a race condition when disposing of the turn socket and the timer to forget the sent request transaction ids
parent 02ff6c5f
...@@ -200,7 +200,14 @@ socket_close (NiceSocket *sock) ...@@ -200,7 +200,14 @@ socket_close (NiceSocket *sock)
SendRequest *r = i->data; SendRequest *r = i->data;
g_source_destroy (r->source); g_source_destroy (r->source);
g_source_unref (r->source); g_source_unref (r->source);
r->source = NULL;
stun_agent_forget_transaction (&priv->agent, r->id);
r->priv = NULL;
if (g_atomic_int_dec_and_test (&r->ref))
g_slice_free (SendRequest, r); g_slice_free (SendRequest, r);
} }
g_queue_free (priv->send_requests); g_queue_free (priv->send_requests);
...@@ -339,22 +346,31 @@ static gboolean ...@@ -339,22 +346,31 @@ static gboolean
priv_forget_send_request (gpointer pointer) priv_forget_send_request (gpointer pointer)
{ {
SendRequest *req = pointer; SendRequest *req = pointer;
GStaticRecMutex *mutex = NULL;
if (req->priv == NULL)
return FALSE;
g_atomic_int_inc (&req->ref); g_atomic_int_inc (&req->ref);
g_static_rec_mutex_lock (&req->priv->nice->mutex); mutex = &req->priv->nice->mutex;
stun_agent_forget_transaction (&req->priv->agent, req->id); g_static_rec_mutex_lock (mutex);
g_source_destroy (req->source); if (req->source) {
g_source_unref (req->source); stun_agent_forget_transaction (&req->priv->agent, req->id);
if (g_queue_index (req->priv->send_requests, req) != -1) { if (g_queue_index (req->priv->send_requests, req) != -1) {
g_queue_remove (req->priv->send_requests, req); g_queue_remove (req->priv->send_requests, req);
(void)g_atomic_int_dec_and_test (&req->ref); (void)g_atomic_int_dec_and_test (&req->ref);
} }
g_static_rec_mutex_unlock (&req->priv->nice->mutex); g_source_destroy (req->source);
g_source_unref (req->source);
req->source = NULL;
}
g_static_rec_mutex_unlock (mutex);
if (g_atomic_int_dec_and_test (&req->ref)) if (g_atomic_int_dec_and_test (&req->ref))
g_slice_free (SendRequest, req); g_slice_free (SendRequest, req);
...@@ -410,6 +426,7 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -410,6 +426,7 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
if (req) { if (req) {
g_source_destroy (req->source); g_source_destroy (req->source);
g_source_unref (req->source); g_source_unref (req->source);
req->source = NULL;
g_queue_remove (priv->send_requests, req); g_queue_remove (priv->send_requests, req);
......
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