Address code analysis issues
[ric-plt/lib/rmr.git] / src / rmr / nng / src / rmr_nng.c
index faae333..3b590fa 100644 (file)
@@ -700,6 +700,7 @@ static void* init(  char* uproto_port, int max_msg_size, int flags ) {
        } else {
                if( (gethostname( wbuf, sizeof( wbuf ) )) != 0 ) {
                        rmr_vlog( RMR_VL_CRIT, "rmr_init: cannot determine localhost name: %s\n", strerror( errno ) );
+                       free( proto_port );
                        return NULL;
                }
                if( (tok = strchr( wbuf, '.' )) != NULL ) {
@@ -726,7 +727,7 @@ static void* init(  char* uproto_port, int max_msg_size, int flags ) {
                ctx->my_ip = get_default_ip( ctx->ip_list );    // and (guess) at what should be the default to put into messages as src
                if( ctx->my_ip == NULL ) {
                        rmr_vlog( RMR_VL_WARN, "rmr_init: default ip address could not be sussed out, using name\n" );
-                       strcpy( ctx->my_ip, ctx->my_name );                     // if we cannot suss it out, use the name rather than a nil pointer
+                       ctx->my_ip = strdup( ctx->my_name );            // if we cannot suss it out, use the name rather than a nil pointer
                }
        }
        if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "default ip address: %s\n", ctx->my_ip );
@@ -747,6 +748,7 @@ static void* init(  char* uproto_port, int max_msg_size, int flags ) {
        if( (state = nng_listen( ctx->nn_sock, bind_info, NULL, NO_FLAGS )) != 0 ) {
                rmr_vlog( RMR_VL_CRIT, "rmr_init: unable to start nng listener for %s: %s\n", bind_info, nng_strerror( state ) );
                nng_close( ctx->nn_sock );
+               free( proto_port );
                free_ctx( ctx );
                return NULL;
        }
@@ -1068,7 +1070,7 @@ extern rmr_mbuf_t* rmr_mt_call( void* vctx, rmr_mbuf_t* mbuf, int call_id, int m
                }
        }
 
-       state = 0;
+       state = -1;                                                                                             
        errno = 0;
        while( chute->mbuf == NULL && ! errno ) {
                if( seconds ) {
@@ -1094,8 +1096,9 @@ extern rmr_mbuf_t* rmr_mt_call( void* vctx, rmr_mbuf_t* mbuf, int call_id, int m
                return NULL;                                    // leave errno as set by sem wait call
        }
 
-       mbuf = chute->mbuf;
-       mbuf->state = RMR_OK;
+       if( (mbuf = chute->mbuf) != NULL ) {
+               mbuf->state = RMR_OK;
+       }
        chute->mbuf = NULL;
 
        return mbuf;