Skip to content

Commit 0f118c3

Browse files
Michal StruweSESA747457
authored andcommitted
session: protect session status against concurrent access
1 parent 1868757 commit 0f118c3

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/session.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,25 @@ nc_session_free(struct nc_session *session, void (*data_free)(void *))
881881
struct ly_in *msg;
882882
struct timespec ts;
883883
void *p;
884+
NC_STATUS status;
884885

885-
if (!session || (session->status == NC_STATUS_CLOSING)) {
886+
if (!session) {
887+
return;
888+
}
889+
890+
if ((session->side == NC_SERVER) && (session->flags & NC_SESSION_CALLHOME)) {
891+
/* CH LOCK */
892+
pthread_mutex_lock(&session->opts.server.ch_lock);
893+
}
894+
895+
status = session->status;
896+
897+
if ((session->side == NC_SERVER) && (session->flags & NC_SESSION_CALLHOME)) {
898+
/* CH UNLOCK */
899+
pthread_mutex_unlock(&session->opts.server.ch_lock);
900+
}
901+
902+
if (status == NC_STATUS_CLOSING) {
886903
return;
887904
}
888905

0 commit comments

Comments
 (0)