Skip to content

Commit eaeb87e

Browse files
author
roman
committed
server config BUGFIX fix thread_data data race
1 parent 6d2fd39 commit eaeb87e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/server_config.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -945,18 +945,22 @@ nc_server_config_destroy_ch_client(struct nc_ch_client *ch_client)
945945
pthread_t tid;
946946
uint16_t i, ch_endpt_count;
947947

948+
/* CH COND LOCK */
949+
pthread_mutex_lock(&ch_client->thread_data->cond_lock);
948950
if (ch_client->thread_data->thread_running) {
949-
/* get tid */
950-
tid = ch_client->tid;
951-
/* CH COND LOCK */
952-
pthread_mutex_lock(&ch_client->thread_data->cond_lock);
953951
ch_client->thread_data->thread_running = 0;
954952
pthread_cond_signal(&ch_client->thread_data->cond);
955953
/* CH COND UNLOCK */
956954
pthread_mutex_unlock(&ch_client->thread_data->cond_lock);
957955

956+
/* get tid */
957+
tid = ch_client->tid;
958+
958959
/* wait for the thread to terminate */
959960
pthread_join(tid, NULL);
961+
} else {
962+
/* CH COND UNLOCK */
963+
pthread_mutex_unlock(&ch_client->thread_data->cond_lock);
960964
}
961965

962966
/* free its members */

0 commit comments

Comments
 (0)