diff --git a/src/rbus/rbus.c b/src/rbus/rbus.c index baeaadff..04583eaf 100644 --- a/src/rbus/rbus.c +++ b/src/rbus/rbus.c @@ -5629,23 +5629,39 @@ rbusError_t rbusEvent_SubscribeExRawData( RBUSLOG_WARN("rbusMessage_RemoveListener:%d", errorcode); } } - memset(rawDataTopic, '\0', strlen(rawDataTopic)); - snprintf(rawDataTopic, RBUS_MAX_NAME_LENGTH, "%s", subscription[i].eventName); - errorcode = rbusMessage_AddPrivateListener(handle, rawDataTopic, _subscribe_rawdata_handler, (void *)(subInternal->sub), subInternal->subscriptionId); - if(errorcode != RBUS_ERROR_SUCCESS) + if(!subInternal) { - RBUSLOG_ERROR("%s: Listener failed err: %d", __FUNCTION__, errorcode); + RBUSLOG_ERROR("%s: subInternal is NULL for event %s", __FUNCTION__, subscription[i].eventName); + errorcode = RBUS_ERROR_INVALID_INPUT; + } + else + { + memset(rawDataTopic, '\0', strlen(rawDataTopic)); + snprintf(rawDataTopic, RBUS_MAX_NAME_LENGTH, "%s", subscription[i].eventName); + errorcode = rbusMessage_AddPrivateListener(handle, rawDataTopic, _subscribe_rawdata_handler, (void *)(subInternal->sub), subInternal->subscriptionId); + if(errorcode != RBUS_ERROR_SUCCESS) + { + RBUSLOG_ERROR("%s: Listener failed err: %d", __FUNCTION__, errorcode); + } } } else { subInternal = rbusEventSubscription_find(handleInfo->eventSubs, subscription[i].eventName, subscription[i].filter, subscription[i].interval, subscription[i].duration, true); - snprintf(rawDataTopic, RBUS_MAX_NAME_LENGTH, "rawdata.%s", subscription[i].eventName); - errorcode = rbusMessage_AddListener(handle, rawDataTopic, - _subscribe_rawdata_handler, (void *)(subInternal->sub), subInternal->subscriptionId); - if(errorcode != RBUS_ERROR_SUCCESS) + if(!subInternal) { - RBUSLOG_ERROR("%s: Listener failed err: %d", __FUNCTION__, errorcode); + RBUSLOG_ERROR("%s: subInternal is NULL for event %s", __FUNCTION__, subscription[i].eventName); + errorcode = RBUS_ERROR_INVALID_INPUT; + } + else + { + snprintf(rawDataTopic, RBUS_MAX_NAME_LENGTH, "rawdata.%s", subscription[i].eventName); + errorcode = rbusMessage_AddListener(handle, rawDataTopic, + _subscribe_rawdata_handler, (void *)(subInternal->sub), subInternal->subscriptionId); + if(errorcode != RBUS_ERROR_SUCCESS) + { + RBUSLOG_ERROR("%s: Listener failed err: %d", __FUNCTION__, errorcode); + } } } HANDLE_EVENTSUBS_MUTEX_UNLOCK(handle);