From 1d64817e2c0b3f2e0a4af658f93c1dcb150ad592 Mon Sep 17 00:00:00 2001 From: sauwming Date: Mon, 9 Oct 2023 17:41:56 +0800 Subject: [PATCH] Use group lock in turn_on_state() --- pjnath/src/pjnath/turn_sock.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pjnath/src/pjnath/turn_sock.c b/pjnath/src/pjnath/turn_sock.c index fc59311159..e5b73d4299 100644 --- a/pjnath/src/pjnath/turn_sock.c +++ b/pjnath/src/pjnath/turn_sock.c @@ -1183,6 +1183,8 @@ static void turn_on_state(pj_turn_session *sess, (*turn_sock->cb.on_state)(turn_sock, old_state, new_state); } + pj_grp_lock_acquire(turn_sock->grp_lock); + /* Make sure user hasn't destroyed us in the callback */ if (turn_sock->sess && new_state == PJ_TURN_STATE_RESOLVED) { pj_turn_session_info info; @@ -1250,6 +1252,7 @@ static void turn_on_state(pj_turn_session *sess, status = pj_sock_socket(turn_sock->af, sock_type, 0, &sock); if (status != PJ_SUCCESS) { turn_sock_destroy(turn_sock, status); + pj_grp_lock_release(turn_sock->grp_lock); return; } @@ -1260,6 +1263,7 @@ static void turn_on_state(pj_turn_session *sess, if (status != PJ_SUCCESS) { pj_sock_close(sock); turn_sock_destroy(turn_sock, status); + pj_grp_lock_release(turn_sock->grp_lock); return; } /* Apply QoS, if specified */ @@ -1271,6 +1275,7 @@ static void turn_on_state(pj_turn_session *sess, { pj_sock_close(sock); turn_sock_destroy(turn_sock, status); + pj_grp_lock_release(turn_sock->grp_lock); return; } @@ -1387,6 +1392,7 @@ static void turn_on_state(pj_turn_session *sess, } if (status != PJ_SUCCESS) { turn_sock_destroy(turn_sock, status); + pj_grp_lock_release(turn_sock->grp_lock); return; } if (turn_sock->cert) { @@ -1398,6 +1404,7 @@ static void turn_on_state(pj_turn_session *sess, if (status != PJ_SUCCESS) { turn_sock_destroy(turn_sock, status); + pj_grp_lock_release(turn_sock->grp_lock); return; } @@ -1415,6 +1422,7 @@ static void turn_on_state(pj_turn_session *sess, if (status != PJ_SUCCESS) { turn_sock_destroy(turn_sock, status); + pj_grp_lock_release(turn_sock->grp_lock); return; } @@ -1457,6 +1465,7 @@ static void turn_on_state(pj_turn_session *sess, pj_sockaddr_print(&info.server, addrtxt, sizeof(addrtxt), 3))); turn_sock_destroy(turn_sock, status); + pj_grp_lock_release(turn_sock->grp_lock); return; } @@ -1465,7 +1474,6 @@ static void turn_on_state(pj_turn_session *sess, */ } - pj_grp_lock_acquire(turn_sock->grp_lock); if (new_state >= PJ_TURN_STATE_DESTROYING && turn_sock->sess) { pj_time_val delay = {0, 0}; @@ -1479,6 +1487,7 @@ static void turn_on_state(pj_turn_session *sess, &delay, TIMER_DESTROY, turn_sock->grp_lock); } + pj_grp_lock_release(turn_sock->grp_lock); }