RIC-939 : Fixes for static error checks

Signed-off-by: Abdulwahid W <abdulwahid.w@nokia.com>
Change-Id: If9f0a0e899d6bd4ea4566cd2b26d194fcf32b3ad
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 11bc04f..0448c63 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,7 +42,7 @@
 
 set( major_version "4" )		# should be automatically populated from git tag later, but until CI process sets a tag we use this
 set( minor_version "8" )
-set( patch_level "3" )
+set( patch_level "4" )
 
 set( install_root "${CMAKE_INSTALL_PREFIX}" )
 set( install_inc "include/rmr" )
diff --git a/src/rmr/common/src/rt_generic_static.c b/src/rmr/common/src/rt_generic_static.c
index 9a8d1fd..56b124e 100644
--- a/src/rmr/common/src/rt_generic_static.c
+++ b/src/rmr/common/src/rt_generic_static.c
@@ -46,6 +46,8 @@
 #include <unistd.h>
 #include <netdb.h>
 #include <pthread.h>
+#include <immintrin.h>
+#include <stdbool.h>
 
 #include <RIC_message_types.h>		// needed for route manager messages
 
@@ -374,7 +376,7 @@
 	must be at the start of a word (i.e. must be immediatly preceeded by whitespace).
 */
 static char* clip( char* buf ) {
-	char*	tok;
+	char*	tok=NULL;
 
 	while( *buf && isspace( *buf ) ) {							// skip leading whitespace
 		buf++;
@@ -390,7 +392,7 @@
 		}
 	}
 
-	for( tok = buf + (strlen( buf ) - 1); tok > buf && isspace( *tok ); tok-- );	// trim trailing spaces too
+	for( tok = buf + (strlen( buf ) - 1); tok > buf && isspace_with_fence( *tok ); tok-- );	// trim trailing spaces too
 	*(tok+1) = 0;
 
 	return buf;
@@ -952,7 +954,7 @@
 	int	grp;							// group number
 	rtable_ent_t const*	rte;			// route table entry added
 	char*	tokens[128];
-	char*	tok;						// pointer into a token or string
+	char*	tok=NULL;						// pointer into a token or string
 	char	wbuf[1024];
 
 	if( ! buf ) {
@@ -967,7 +969,7 @@
 	while( *buf && isspace( *buf ) ) {							// skip leading whitespace
 		buf++;
 	}
-	for( tok = buf + (strlen( buf ) - 1); tok > buf && isspace( *tok ); tok-- );	// trim trailing spaces too
+	for( tok = buf + (strlen( buf ) - 1); tok > buf && isspace_with_fence( *tok ); tok-- );	// trim trailing spaces too
 	*(tok+1) = 0;
 
 	memset( tokens, 0, sizeof( tokens ) );
@@ -1539,6 +1541,7 @@
 		rt = NULL;
 	}
 
+	pthread_mutex_destroy(ctx->rtgate);
 	rt = uta_rt_clone( ctx, ctx->rtable, rt, all );		// also sets the ephash pointer
 	if( rt != NULL ) {									// very small chance for nil, but not zero, so test
 		rt->ref_count = 0;								// take no chances; ensure it's 0!
@@ -1689,4 +1692,10 @@
 	}
 	pthread_mutex_unlock( ctx->rtgate );
 }
+
+int isspace_with_fence(int c) {
+	_mm_lfence();
+	return isspace( c );
+}
+
 #endif
diff --git a/src/rmr/si/src/rmr_si.c b/src/rmr/si/src/rmr_si.c
index bd858de..52007fc 100644
--- a/src/rmr/si/src/rmr_si.c
+++ b/src/rmr/si/src/rmr_si.c
@@ -796,6 +796,7 @@
 		return init_err( "unable to allocate ep hash\n", ctx, proto_port, ENOMEM );
 	}
 
+	pthread_mutex_destroy(ctx->rtgate);
 	ctx->rtable = rt_clone_space( ctx, NULL, NULL, 0 );	// create an empty route table so that wormhole/rts calls can be used
 	if( flags & RMRFL_NOTHREAD ) {						// no thread prevents the collector start for very special cases
 		ctx->rtable_ready = 1;							// route based sends will always fail, but rmr is ready for the non thread case
diff --git a/src/rmr/si/src/si95/sisendt.c b/src/rmr/si/src/si95/sisendt.c
index 26c5f93..752a955 100644
--- a/src/rmr/si/src/si95/sisendt.c
+++ b/src/rmr/si/src/si95/sisendt.c
@@ -69,7 +69,7 @@
 		for( tpptr = gptr->tplist; tpptr != NULL && tpptr->fd != fd; tpptr = tpptr->next ) ; //  find the block if out of map's range
 	}
 	if( tpptr != NULL ) {
-		if( (fd = tpptr->fd) < 0 ) {			// fd user given might not be real, and this might be closed already
+		if( (fd = tpptr->fd) < 0 || (fd = tpptr->fd) >= FD_SETSIZE ) {			// fd user given might not be real, and this might be closed already
 			errno = EBADFD;
 			return SI_ERROR;
 		}