diff --git a/src/komodo_events.h b/src/komodo_events.h index b5178d396..828be84aa 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -18,18 +18,21 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen) { - struct komodo_event *ep; uint16_t len = (uint16_t)(sizeof(*ep) + datalen); - portable_mutex_lock(&komodo_mutex); - ep = (struct komodo_event *)calloc(1,len); - ep->len = len; - ep->height = height; - ep->type = type; - strcpy(ep->symbol,symbol); - if ( datalen != 0 ) - memcpy(ep->space,data,datalen); - sp->Komodo_events = (struct komodo_event **)realloc(sp->Komodo_events,(1 + sp->Komodo_numevents) * sizeof(*sp->Komodo_events)); - sp->Komodo_events[sp->Komodo_numevents++] = ep; - portable_mutex_unlock(&komodo_mutex); + struct komodo_event *ep=0; uint16_t len = (uint16_t)(sizeof(*ep) + datalen); + if ( sp != 0 ) + { + portable_mutex_lock(&komodo_mutex); + ep = (struct komodo_event *)calloc(1,len); + ep->len = len; + ep->height = height; + ep->type = type; + strcpy(ep->symbol,symbol); + if ( datalen != 0 ) + memcpy(ep->space,data,datalen); + sp->Komodo_events = (struct komodo_event **)realloc(sp->Komodo_events,(1 + sp->Komodo_numevents) * sizeof(*sp->Komodo_events)); + sp->Komodo_events[sp->Komodo_numevents++] = ep; + portable_mutex_unlock(&komodo_mutex); + } return(ep); } @@ -124,13 +127,16 @@ void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height) void komodo_setkmdheight(struct komodo_state *sp,int32_t kmdheight,uint32_t timestamp) { - if ( kmdheight > sp->SAVEDHEIGHT ) + if ( sp != 0 ) { - sp->SAVEDHEIGHT = kmdheight; - sp->SAVEDTIMESTAMP = timestamp; + if ( kmdheight > sp->SAVEDHEIGHT ) + { + sp->SAVEDHEIGHT = kmdheight; + sp->SAVEDTIMESTAMP = timestamp; + } + if ( kmdheight > sp->CURRENT_HEIGHT ) + sp->CURRENT_HEIGHT = kmdheight; } - if ( kmdheight > sp->CURRENT_HEIGHT ) - sp->CURRENT_HEIGHT = kmdheight; } void komodo_eventadd_kmdheight(struct komodo_state *sp,char *symbol,int32_t height,int32_t kmdheight,uint32_t timestamp)