}
}
- for( rec = fbuf; rec && *rec; rec = eor+1 ) {
+ rec = fbuf;
+ while( rec && *rec ) {
rcount++;
if( (eor = strchr( rec, '\n' )) != NULL ) {
*eor = 0;
}
parse_rt_rec( ctx, NULL, rec, vlevel ); // no pvt context as we can't ack
+
+ rec = eor+1;
}
if( DEBUG ) rmr_vlog_force( RMR_VL_DEBUG, "rmr_read_static: seed route table successfully parsed: %d records\n", rcount );
return (int ) (t % size);
}
-/* delete element pointed to by eptr at hash loc hv */
+/*
+ Delete element pointed to by eptr which is assumed to be
+ a member of the list at symtab[i].
+*/
static void del_ele( Sym_tab *table, int hv, Sym_ele *eptr )
{
Sym_ele **sym_tab;
}
}
+/*
+ Delete the head element from table[i]. This isn't really
+ needed, but keeps code analysers from claiming that memory
+ is being used after it is freed.
+*/
+static void del_head_ele( Sym_tab *table, int hv ) {
+ Sym_ele **sym_tab;
+ Sym_ele *eptr; // first in list
+
+
+ if( hv < 0 || hv >= table->size ) {
+ return;
+ }
+
+ sym_tab = table->symlist;
+ if( (eptr = sym_tab[hv]) != NULL ) // not an empty element; yank it off
+ {
+ if( (sym_tab[hv] = eptr->next) != NULL ) { // bump list to next if not the only thing here
+ sym_tab[hv]->prev = NULL; // new head
+ }
+ eptr->next = NULL; // take no chances
+
+ if( eptr->class && eptr->name ) { // class 0 entries are numeric, so name is NOT a pointer
+ free( (void *) eptr->name );
+ }
+
+ free( eptr );
+
+ table->deaths++;
+ table->inhabitants--;
+ }
+}
+
/*
Determine if these are the same.
*/
table = (Sym_tab *) vtable;
sym_tab = table->symlist;
- for( i = 0; i < table->size; i++ )
- while( sym_tab[i] )
- del_ele( table, i, sym_tab[i] );
+ for( i = 0; i < table->size; i++ ) {
+ while( sym_tab[i] ) {
+ del_head_ele( table, i ); // delete the head element (and keep bloody sonar from claiming use after free)
+ }
+ }
}
/*
st = (Sym_tab *) vst;
- if( st && (list = st->symlist) != NULL && user_fun != NULL )
- for( i = 0; i < st->size; i++ )
- for( se = list[i]; se; se = next ) /* using next allows user to delete via this */
- {
- if( se ) {
- next = se->next;
- if( class == se->class ) {
- user_fun( st, se, se->name, se->val, user_data );
- }
+ if( st && (list = st->symlist) != NULL && user_fun != NULL ) {
+ for( i = 0; i < st->size; i++ ) {
+ se = list[i];
+ while( se ) {
+ next = se->next; // allow callback to delete from the list w/o borking us
+ if( class == se->class ) {
+ user_fun( st, se, se->name, se->val, user_data );
}
+ se = next;
}
+ }
+ }
}
strcat src is freed as a convenience. Max is the max amount
that target can accept; we don't bang on if src len is
larger than max. Return is the size of src; 0 if the
- target was not modified. If target is not modified, then
- src is NOT released.
+ target was not modified.
+
+ Source is ALWAYS freed!
*/
static int bang_on( char* target, char* src, int max ) {
int len;
len = strlen( src );
if( (rc = len <= max ? len : 0 ) > 0 ) { // if it fits, add it.
strcat( target, src );
- free( src );
}
}
+ if( src ) {
+ free( src );
+ }
return rc;
}
} 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 ) {
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 );
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;
}
}
}
- state = 0;
+ state = -1;
errno = 0;
while( chute->mbuf == NULL && ! errno ) {
if( seconds ) {
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;
nm->alloc_len = mlen; // length of allocated payload
if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "clone values: mty=%d sid=%d len=%d alloc=%d\n", nm->mtype, nm->sub_id, nm->len, nm->alloc_len );
- nm->xaction = hdr->xid; // reference xaction
+ nm->xaction = &hdr->xid[0]; // point at transaction id in header area
nm->state = old_msg->state; // fill in caller's state (likely the state of the last operation)
nm->flags = old_msg->flags | MFL_ZEROCOPY; // this is a zerocopy sendable message
memcpy( nm->payload, old_msg->payload, old_msg->len );
nm->len = old_msg->len; // length of data in the payload
nm->alloc_len = mlen; // length of allocated payload
- nm->xaction = hdr->xid; // reference xaction
+ nm->xaction = &hdr->xid[0]; // point at transaction id in header area
nm->state = old_msg->state; // fill in caller's state (likely the state of the last operation)
nm->flags = old_msg->flags | MFL_ZEROCOPY; // this is a zerocopy sendable message
memcpy( nm->payload, old_msg->payload, old_msg->len );
}
}
- mbuf->flags |= MFL_ADDSRC; // turn on so if user app tries to send this buffer we reset src
+ if( mbuf != NULL ) {
+ mbuf->flags |= MFL_ADDSRC; // turn on so if user app tries to send this buffer we reset src
+ }
return mbuf;
}
}
mbuf = chute->mbuf;
- mbuf->state = RMR_OK;
+ if( mbuf != NULL ) {
+ mbuf->state = RMR_OK;
+ }
chute->mbuf = NULL;
return mbuf;
dstr++;
pstr = strchr( dstr, ']' );
if( *pstr != ']' ) {
+ free( fptr );
return -1;
}
freeaddrinfo( list ); // ditch system allocated memory
}
- free( dstr );
+ free( fptr );
return rlen;
}
*/
extern int SIaddress( void *src, void **dest, int type ) {
struct sockaddr_in *addr; // pointer to the address
+ struct sockaddr_in6 *addr6; // ip6 has a different layout
unsigned char *num; // pointer at the address number
+ uint8_t* byte; // pointer at the ipv6 address byte values
char wbuf[256]; // work buffer
int i;
int rlen = 0; // return len - len of address struct or string
switch( type ) {
case AC_TODOT: // convert from a struct to human readable "dotted decimal"
addr = (struct sockaddr_in *) src;
- num = (char *) &addr->sin_addr.s_addr; // point at the long
if( addr->sin_family == AF_INET6 ) {
- sprintf( wbuf, "[%u:%u:%u:%u:%u:%u]:%d",
- *(num+0), *(num+1), *(num+2),
- *(num+3), *(num+4), *(num+5) ,
- (int) ntohs( addr->sin_port ) );
+ addr6 = (struct sockaddr_in6 *) src; // really an ip6 struct
+ byte = (uint8_t *) &addr6->sin6_addr;
+ sprintf( wbuf, "[%u:%u:%u:%u:%u:%u]:%d",
+ *(byte+0), *(byte+1), *(byte+2),
+ *(byte+3), *(byte+4), *(byte+5) ,
+ (int) ntohs( addr6->sin6_port ) );
} else {
+ num = (char *) &addr->sin_addr.s_addr; // point at the long
sprintf( wbuf, "%u.%u.%u.%u;%d", *(num+0), *(num+1), *(num+2), *(num+3), (int) ntohs(addr->sin_port) );
}
case AC_TOADDR6: // from hostname;port string to address for send etc
return SIgenaddr( src, PF_INET6, IPPROTO_TCP, SOCK_STREAM, (struct sockaddr **) dest );
- break;
case AC_TOADDR: // from dotted decimal to address struct ip4
return SIgenaddr( src, PF_INET, IPPROTO_TCP, SOCK_STREAM, (struct sockaddr **) dest );
- break;
}
return rlen;
FD_ZERO( &gptr->writefds );
FD_ZERO( &gptr->execpfds );
- for( tpptr = gptr->tplist; tpptr != NULL; tpptr = nextb ) {
- nextb = tpptr->next;
+ tpptr = gptr->tplist;
+ while( tpptr != NULL ) {
+ nextb = tpptr->next; // point past allowing for a delete
+
if( tpptr->flags & TPF_DELETE ) {
if( tpptr->fd >= 0 ) { // wasn't closed for some reason
SIterm( gptr, tpptr );
}
}
}
+
+ tpptr = nextb;
}
}
// for( tpptr = gptr->tplist; tpptr != NULL; tpptr = tpptr->next )
for( tpptr = gptr->tplist; tpptr != NULL; tpptr = nextone )
- {
- nextone = tpptr->next; // prevent coredump if we delete the session
+ tpptr = gptr->tplist;
+ while( tpptr != NULL ) {
+ nextone = tpptr->next; // allow for a delete in loop
if( tpptr->squeue != NULL && (FD_ISSET( tpptr->fd, &gptr->writefds )) )
SIsend( gptr, tpptr ); // send if clear to send
}
} // end tcp read
} // end if event on this fd
+
+ tpptr = nextone;
} // end for each fd in the list
} // end if not in shutdown
case TP_BLK: // we assume its off the list
tp = (struct tp_blk *) bp;
- for( iptr = tp->squeue; iptr; iptr = inext ) // trash any pending send buffers
- {
+ iptr = tp->squeue;
+ while( iptr != NULL ) {
inext = iptr->next;
+
free( iptr->data ); // we could recurse, but that seems silly
free( iptr->addr );
free( iptr );
+
+ iptr = inext;
}
if( tp->fd >= 0 ) {
}
if( pstat > 0 && (! (gptr->flags & GIF_SHUTDOWN)) ) {
- for( tpptr = gptr->tplist; tpptr != NULL; tpptr = nextone ) {
+ tpptr = gptr->tplist;
+ while( tpptr != NULL ) {
nextone = tpptr->next; // prevent issues if we delete the block during loop
if( tpptr->fd >= 0 ) {
}
}
} // if still good fd
+
+ tpptr = nextone;
}
}
} while( gptr->tplist != NULL && !(gptr->flags & GIF_SHUTDOWN) );
nm->len = old_msg->len; // length of data in the payload
nm->alloc_len = mlen; // length of allocated payload
- nm->xaction = hdr->xid; // reference xaction
+ nm->xaction = &hdr->xid[0]; // reference xaction
nm->state = old_msg->state; // fill in caller's state (likely the state of the last operation)
nm->flags = old_msg->flags | MFL_ZEROCOPY; // this is a zerocopy sendable message
memcpy( nm->payload, old_msg->payload, old_msg->len );
nm->len = old_msg->len; // length of data in the payload
nm->alloc_len = mlen; // length of allocated payload
- nm->xaction = hdr->xid; // reference xaction
+ nm->xaction = &hdr->xid[0]; // reference xaction
nm->state = old_msg->state; // fill in caller's state (likely the state of the last operation)
nm->flags = old_msg->flags | MFL_ZEROCOPY; // this is a zerocopy sendable message
memcpy( nm->payload, old_msg->payload, old_msg->len );
if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "reallocate for payload increase. new message size: %d\n", (int) mlen );
if( (nm->tp_buf = (char *) malloc( sizeof( char ) * mlen )) == NULL ) {
rmr_vlog( RMR_VL_CRIT, "rmr_realloc_payload: cannot get memory for zero copy buffer. bytes requested: %d\n", (int) mlen );
+ free( nm );
return NULL;
}