Address complaints by code scanner

This change addresses complaints generated by a recent code scan

Issue-ID: RIC-673

Signed-off-by: E. Scott Daniels <daniels@research.att.com>
Change-Id: I230449eced30477e13ec3eb867a5e16f67d4fae8
diff --git a/CHANGES_CORE.txt b/CHANGES_CORE.txt
index a3e1373..fa92133 100644
--- a/CHANGES_CORE.txt
+++ b/CHANGES_CORE.txt
@@ -5,6 +5,9 @@
 # API and build change  and fix summaries. Doc correctsions
 # and/or changes are not mentioned here; see the commit messages.
 
+2020 November 4; Version 4.4.1
+	Changes to correct complaints generated by a code scan. (RIC-673)
+
 2020 November 4; Version 4.4.0
 	Changes to address a potential race condition when route tables
 	arrive in quick succession.  (RIC-674)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2ac15d7..dd189f4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,7 +41,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 "4" )
-set( patch_level "0" )
+set( patch_level "1" )
 
 set( install_root "${CMAKE_INSTALL_PREFIX}" )
 set( install_inc "include/rmr" )
diff --git a/docs/rel-notes.rst b/docs/rel-notes.rst
index a37304b..7b3d7a7 100644
--- a/docs/rel-notes.rst
+++ b/docs/rel-notes.rst
@@ -22,6 +22,14 @@
 version 4.0.0, the RMR versions should no longer skip.
 
 
+2020 November 4; Version 4.4.1
+------------------------------
+
+Changes to correct complaints generated by a code scan.
+(Ric-673)
+
+
+
 2020 November 4; Version 4.4.0
 ------------------------------
 
diff --git a/src/rmr/common/src/logging.c b/src/rmr/common/src/logging.c
index 65fb745..0407eed 100644
--- a/src/rmr/common/src/logging.c
+++ b/src/rmr/common/src/logging.c
@@ -156,6 +156,8 @@
 
 	vsnprintf( body, sizeof( msg ) - (hlen+2), fmt, argp );			// add in user message formatting it along the way
 	fprintf( stderr, "%s", msg );									// we grew from printfs so all existing msg have \n; assume there
+
+	va_end( argp );
 }
 
 /*
@@ -190,6 +192,8 @@
 
 	vsnprintf( body, sizeof( msg ) - (hlen+2), fmt, argp );			// add in user message formatting it along the way
 	fprintf( stderr, "%s", msg );									// we grew from printfs so all existing msg have \n; assume there
+
+	va_end( argp );
 }
 
 // -------------------- public functions that are needed -----------------
diff --git a/src/rmr/common/src/ring_static.c b/src/rmr/common/src/ring_static.c
index b54d815..da2a9bd 100644
--- a/src/rmr/common/src/ring_static.c
+++ b/src/rmr/common/src/ring_static.c
@@ -85,12 +85,12 @@
 	}
 
 	r->nelements = size;		// because we always have an empty element when full
-	if( (r->data = (void **) malloc( sizeof( void** ) * (r->nelements + 1) )) == NULL ) {
+	if( (r->data = (void **) malloc( sizeof( void* ) * (r->nelements + 1) )) == NULL ) {
 		free( r );
 		return NULL;
 	}
 
-	memset( r->data, 0, sizeof( void** ) * r->nelements );
+	memset( r->data, 0, sizeof( void* ) * r->nelements );
 	r->pfd = eventfd( 0, EFD_SEMAPHORE | EFD_NONBLOCK );		// in semaphore mode counter is maintained with each insert/extract
 	return (void *) r;
 }
diff --git a/src/rmr/common/src/rt_generic_static.c b/src/rmr/common/src/rt_generic_static.c
index 4f8fa12..532a6bf 100644
--- a/src/rmr/common/src/rt_generic_static.c
+++ b/src/rmr/common/src/rt_generic_static.c
@@ -712,15 +712,13 @@
 		}
 		parse_meid_ar( ctx->new_rtable,  tokens[1], tokens[2], vlevel );
 		ctx->new_rtable->mupdates++;
+		return;
 	}
 
-	if( strcmp( tokens[0], "mme_del" ) == 0 ) {
-		if( ntoks < 2 ) {
-			rmr_vlog( RMR_VL_ERR, "meid_parse: mme_del record didn't have enough tokens\n" );
-			return;
-		}
+	if( strcmp( tokens[0], "mme_del" ) == 0 ) {						// ntoks < 2 already validated
 		parse_meid_del( ctx->new_rtable,  tokens[1], vlevel );
 		ctx->new_rtable->mupdates++;
+		return;
 	}
 }
 
diff --git a/src/rmr/common/src/rtc_static.c b/src/rmr/common/src/rtc_static.c
index 2deef8e..9aca092 100644
--- a/src/rmr/common/src/rtc_static.c
+++ b/src/rmr/common/src/rtc_static.c
@@ -78,8 +78,9 @@
 		if( vfd >= 0 ) {
 			wbuf[0] = 0;
 			lseek( vfd, 0, 0 );
-			read( vfd, wbuf, 10 );
-			vlevel = atoi( wbuf );
+			if( read( vfd, wbuf, 10 ) > 0 ) {
+				vlevel = atoi( wbuf );
+			}
 		}
 
 		read_static_rt( ctx, vlevel );						// seed the route table if one provided
@@ -98,8 +99,9 @@
 	if( vfd >= 0 ) {					// if file is open, read current value
 		rbuf[0] = 0;
 		lseek( vfd, 0, 0 );
-		read( vfd, rbuf, 10 );
-		vlevel = atoi( rbuf );
+		if( read( vfd, rbuf, 10 ) > 0 ) {
+			vlevel = atoi( rbuf );
+		}
 	}
 
 	return vlevel;
diff --git a/src/rmr/common/src/tools_static.c b/src/rmr/common/src/tools_static.c
index a69db35..cc95fc1 100644
--- a/src/rmr/common/src/tools_static.c
+++ b/src/rmr/common/src/tools_static.c
@@ -80,7 +80,7 @@
 	char const*	sp;
 	int			n;		// num moved
 
-	if( dest == NULL && src == NULL ) {
+	if( dest == NULL || src == NULL ) {
 		return -1;
 	}
 
@@ -334,7 +334,7 @@
 	struct	ifaddrs *ele;		// pointer into the list
 	char	octs[NI_MAXHOST+1];
 	char	wbuf[NI_MAXHOST+128];
-	char*	fmt;
+	char*	fmt = NULL;			// address format (v4 or v6)
 	char*	envp;				// at the environment var if there
 	char*	target_if = NULL;	// target interface supplied by ENV_BIND_IF
 	char*	tok;
@@ -379,7 +379,7 @@
 					}
 				}
 
-				if( *octs ) {
+				if( *octs  && fmt != NULL ) {				// possible that we didn't recognise the format (v4 or v6), don't try if we didn't
 					if( (tok = strchr( octs, '%' )) != NULL ) {			// for unknown reasons some ip6 addrs have %if-name appended; truncate
 						*tok = 0;
 					}
diff --git a/src/rmr/si/src/rmr_si.c b/src/rmr/si/src/rmr_si.c
index 9b2444a..85e058b 100644
--- a/src/rmr/si/src/rmr_si.c
+++ b/src/rmr/si/src/rmr_si.c
@@ -544,7 +544,7 @@
 	uta_ctx_t*	ctx = NULL;
 	char	bind_info[256];				// bind info
 	char*	proto = "tcp";				// pointer into the proto/port string user supplied
-	char*	port;
+	char*	port;						// pointer into the proto_port buffer at the port value
 	char*	interface = NULL;			// interface to bind to (from RMR_BIND_IF, 0.0.0.0 if not defined)
 	char*	proto_port;
 	char	wbuf[1024];					// work buffer
@@ -660,6 +660,7 @@
 	ctx->my_name = (char *) malloc( sizeof( char ) * RMR_MAX_SRC );
 	if( snprintf( ctx->my_name, RMR_MAX_SRC, "%s:%s", wbuf, port ) >= RMR_MAX_SRC ) {			// our registered name is host:port
 		rmr_vlog( RMR_VL_CRIT, "rmr_init: hostname + port must be less than %d characters; %s:%s is not\n", RMR_MAX_SRC, wbuf, port );
+		free( proto_port );					// some scanners complain that port is not freed; it CANNOT be
 		return NULL;
 	}
 
diff --git a/src/rmr/si/src/rtable_si_static.c b/src/rmr/si/src/rtable_si_static.c
index e0e3dc6..c348b7f 100644
--- a/src/rmr/si/src/rtable_si_static.c
+++ b/src/rmr/si/src/rtable_si_static.c
@@ -177,12 +177,12 @@
 		}
 		memset( rrg, 0, sizeof( *rrg ) );
 
-		if( (rrg->epts = (endpoint_t **) malloc( sizeof( endpoint_t ) * MAX_EP_GROUP )) == NULL ) {
+		if( (rrg->epts = (endpoint_t **) malloc( sizeof( endpoint_t* ) * MAX_EP_GROUP )) == NULL ) {
 			rmr_vlog( RMR_VL_WARN, "rmr_add_ep: malloc failed for group endpoint array: group=%d\n", group );
 			free( rrg );
 			return NULL;
 		}
-		memset( rrg->epts, 0, sizeof( endpoint_t ) * MAX_EP_GROUP );
+		memset( rrg->epts, 0, sizeof( endpoint_t* ) * MAX_EP_GROUP );
 
 		rte->rrgroups[group] = rrg;
 
@@ -224,7 +224,7 @@
 
 	if( PARANOID_CHECKS ) {
 		if( ctx == NULL ) {
-			if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "epsock_byname: parinoia check pop ctx=%p\n", ctx, rt );
+			if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "epsock_byname: parinoia check pop ctx=%p rt=%p\n", ctx, rt );
 			return FALSE;
 		}
 		rt = get_rt( ctx );				// get active rt and bump ref count
diff --git a/src/rmr/si/src/si95/siestablish.c b/src/rmr/si/src/si95/siestablish.c
index 53c8db5..d3068e0 100644
--- a/src/rmr/si/src/si95/siestablish.c
+++ b/src/rmr/si/src/si95/siestablish.c
@@ -94,6 +94,9 @@
 
 		alen = SIgenaddr( abuf, protocol, family, tptr->type, &addr );	//  family == 0 for type that suits the address passed in
 		if( alen <= 0 ) {
+			if( addr != NULL ) {
+				free( addr );		// not needed, but scanners complain if we don't overtly do this
+			}
 			return NULL;
 		}
 
@@ -190,6 +193,9 @@
 
 		alen = SIgenaddr( abuf, protocol, family, tptr->type, &addr );	//  family == 0 for type that suits the address passed in
 		if( alen <= 0 ) {
+			if( addr != NULL ) {		// not needed, but scanners complain if we don't overtly do this
+				free( addr );
+			}
 			return NULL;
 		}
 
diff --git a/src/rmr/si/src/si95/sipoll.c b/src/rmr/si/src/si95/sipoll.c
index d736d14..aa85e8b 100644
--- a/src/rmr/si/src/si95/sipoll.c
+++ b/src/rmr/si/src/si95/sipoll.c
@@ -42,9 +42,6 @@
 
 extern int SIpoll( struct ginfo_blk *gptr, int msdelay )
 {
- //extern int deaths;       //  number of children that died and are zombies
- //extern int sigflags;     //  flags set by the signal handler routine
-
  int fd;                       //  file descriptor for use in this routine
  int ((*cbptr)());             //  pointer to callback routine to call
  int status = SI_OK;              //  return status
@@ -113,7 +110,7 @@
 
          if( tpptr->flags & TPF_LISTENFD )     //  listen port setup by init?
           {                                    //  yes-assume new session req
-           status = SInewsession( gptr, tpptr );    //  make new session
+           SInewsession( gptr, tpptr );		   //  cannot do anything about failure, so ignore status
           }
          else                              //  data received on a regular port
           if( tpptr->type == SOCK_DGRAM )          //  udp socket?
@@ -128,6 +125,7 @@
                 status = (*cbptr)( gptr->cbtab[SI_CB_RDATA].cbdata, gptr->rbuf, status, buf );
                 SIcbstat( gptr, status, SI_CB_RDATA );    //  handle status
 				free( buf );
+				buf = NULL;						// just to be safe
                }                              //  end if call back was defined
              }                                //  end if status was ok
             free( uaddr );
diff --git a/src/rmr/si/src/si95/siwait.c b/src/rmr/si/src/si95/siwait.c
index 128c1a7..c14c5a9 100644
--- a/src/rmr/si/src/si95/siwait.c
+++ b/src/rmr/si/src/si95/siwait.c
@@ -78,6 +78,7 @@
 
 	if( gptr->magicnum != MAGICNUM ) {				//  if not a valid ginfo block 
 		rmr_vlog( RMR_VL_CRIT, "SI95: wait: bad global info struct magic number is wrong\n" );
+		free( ibuf );
 		return SI_ERROR;
 	}