server session BUGFIX ssh channel on pollsession creation locking updated
diff --git a/src/session_p.h b/src/session_p.h
index 04c2301..234b429 100644
--- a/src/session_p.h
+++ b/src/session_p.h
@@ -296,6 +296,10 @@
 
 int nc_timedlock(pthread_mutex_t *lock, int timeout);
 
+int nc_ps_lock(struct nc_pollsession *ps);
+
+int nc_ps_unlock(struct nc_pollsession *ps);
+
 /**
  * @brief Fill libyang context in \p session. Context models are based on the stored session
  *        capabilities. If the server does not support \<get-schema\>, the models are searched
diff --git a/src/session_server.c b/src/session_server.c
index c448946..1316d87 100644
--- a/src/session_server.c
+++ b/src/session_server.c
@@ -473,7 +473,7 @@
     return -1;
 }
 
-static int
+int
 nc_ps_lock(struct nc_pollsession *ps)
 {
     int ret;
@@ -535,7 +535,7 @@
     return 0;
 }
 
-static int
+int
 nc_ps_unlock(struct nc_pollsession *ps)
 {
     int ret;
diff --git a/src/session_server_ssh.c b/src/session_server_ssh.c
index fb2babe..3067813 100644
--- a/src/session_server_ssh.c
+++ b/src/session_server_ssh.c
@@ -1179,7 +1179,9 @@
     }
 
     /* LOCK */
-    pthread_mutex_lock(&ps->lock);
+    if (nc_ps_lock(ps)) {
+        return -1;
+    }
 
     for (i = 0; i < ps->session_count; ++i) {
         if ((ps->sessions[i]->status == NC_STATUS_RUNNING) && (ps->sessions[i]->ti_type == NC_TI_LIBSSH)
@@ -1203,7 +1205,7 @@
     }
 
     /* UNLOCK */
-    pthread_mutex_unlock(&ps->lock);
+    nc_ps_unlock(ps);
 
     if (!new_session) {
         ERR("No session with a NETCONF SSH channel ready was found.");