server session BUGFIX wait for ch thread when freeing session
Fixes #51
diff --git a/src/session_server.c b/src/session_server.c
index 73126f3..576a9cd 100644
--- a/src/session_server.c
+++ b/src/session_server.c
@@ -2799,6 +2799,11 @@
goto ch_client_remove;
}
+ if (session->status == NC_STATUS_CLOSING) {
+ /* session is being freed, finish thread */
+ goto ch_client_remove;
+ }
+
/* check whether the client was not removed */
/* LOCK */
client = nc_server_ch_client_lock(data->client_name, 0, NULL);
@@ -2834,13 +2839,10 @@
return 0;
ch_client_remove:
- /* make the session a standard one */
pthread_cond_destroy(session->opts.server.ch_cond);
free(session->opts.server.ch_cond);
session->opts.server.ch_cond = NULL;
- session->flags &= ~NC_SESSION_CALLHOME;
-
/* CH UNLOCK */
pthread_mutex_unlock(session->opts.server.ch_lock);
@@ -2848,6 +2850,9 @@
free(session->opts.server.ch_lock);
session->opts.server.ch_lock = NULL;
+ /* make the session a standard one */
+ session->flags &= ~NC_SESSION_CALLHOME;
+
return 1;
}