client session CHANGE added session checks during hello sending
diff --git a/src/session_client.c b/src/session_client.c
index 7866511..d436727 100644
--- a/src/session_client.c
+++ b/src/session_client.c
@@ -503,6 +503,13 @@
         }
 
         if (!mod) {
+            if (session->status != NC_STATUS_RUNNING) {
+                /* something bad heppened, discard the session */
+                ERR("Session %d: invalid session, discarding.", nc_session_get_id(session));
+                ret = 1;
+                goto cleanup;
+            }
+
             /* all loading ways failed, the schema will be ignored in the received data */
             WRN("Failed to load schema \"%s@%s\".", name, revision ? revision : "<latest>");
             session->flags |= NC_SESSION_CLIENT_NOT_STRICT;
@@ -583,7 +590,7 @@
         usleep(1000);
     }
     if (msg == NC_MSG_ERROR) {
-        ERR("Session %u: failed to send request for yang-library data, trying to use capabilities list.",
+        ERR("Session %u: failed to send request for yang-library data.",
             session->id);
         goto cleanup;
     }
@@ -742,6 +749,11 @@
     ly_set_free(imports);
     ly_set_free(features);
 
+    if (session->status != NC_STATUS_RUNNING) {
+        ERR("Session %d: invalid session, discarding.", nc_session_get_id(session));
+        ret = -1;
+    }
+
     return ret;
 }
 
@@ -795,14 +807,14 @@
         if (r == -1) {
             goto cleanup;
         } else if (r == 1) {
+            VRB("Session %d: trying to use capabilities instead of ietf-yang-library data.", nc_session_get_id(session));
             /* try to use standard capabilities */
             goto capabilities;
         }
     } else {
 capabilities:
 
-        r = nc_ctx_fill_cpblts(session, old_clb, old_data);
-        if (r) {
+        if (nc_ctx_fill_cpblts(session, old_clb, old_data)) {
             goto cleanup;
         }
     }