result = RMPConstructObserveResPayload(g_GatewayID, g_sequenceNumber,
updatedTableList, false,
&updatedPayload);
- RM_VERIFY_SUCCESS(result, OC_STACK_OK);
+ if (OC_STACK_OK != result)
+ {
+ OC_LOG_V(ERROR, TAG, "RMPConstructObserveResPayload failed[%d]", result);
+ RMPFreePayload(updatedPayload);
+ goto exit;
+ }
result = RMSendNotificationToAll(updatedPayload);
- RM_VERIFY_SUCCESS(result, OC_STACK_OK);
RMPFreePayload(updatedPayload);
+ RM_VERIFY_SUCCESS(result, OC_STACK_OK);
exit:
u_linklist_free(&updatedTableList);
if (gatewayId == g_GatewayID)
{
OC_LOG(INFO, TAG, "-------------->Own entry, continue!!");
+ RTMFreeGatewayRouteTable(&gatewayTableList);
return OC_STACK_ERROR;
}
// Convert OCDevAddr to endpoint address
OC_LOG(ERROR, TAG, "Few packet drops are found, sequence number is not matching");
// Send a observe request to the gateway.
RMSendObserveRequest(devAddr, NULL);
+ RTMFreeGatewayRouteTable(&gatewayTableList);
return result;
}
else if (OC_STACK_DUPLICATE_REQUEST == result)
{
OC_LOG(ERROR, TAG, "Same sequence number is received");
+ RTMFreeGatewayRouteTable(&gatewayTableList);
return result;
}
}
// Create a list to add the updated entries and notify the observers
u_linklist_t *updatedTableList = u_linklist_create();
+ if(!updatedTableList)
+ {
+ OC_LOG(DEBUG, TAG, "Failed to allocate memory");
+ return OC_STACK_NO_MEMORY;
+ }
+
u_linklist_t *alternativeRouteList = u_linklist_create();
+ if(!alternativeRouteList)
+ {
+ OC_LOG(DEBUG, TAG, "Failed to allocate memory");
+ return OC_STACK_NO_MEMORY;
+ }
+
OCRepPayload *updatedPayload = NULL;
if (false == doRemoveEntry)
{
result = RMPConstructObserveResPayload(g_GatewayID, g_sequenceNumber,
updatedTableList, false,
&updatedPayload);
+ RM_VERIFY_SUCCESS(result, OC_STACK_OK);
goto sendNotification;
}
}
result = RMPConstructObserveResPayload(g_GatewayID, g_sequenceNumber,
alternativeRouteList, false,
&removeTablePayload);
- RM_VERIFY_SUCCESS(result, OC_STACK_OK);
+ if (OC_STACK_OK != result)
+ {
+ OC_LOG_V(ERROR, TAG, "RMPConstructObserveResPayload failed[%d]", result);
+ RMPFreePayload(removeTablePayload);
+ goto exit;
+ }
result = RMSendNotificationToAll(removeTablePayload);
- RM_VERIFY_SUCCESS(result, OC_STACK_OK);
RMPFreePayload(removeTablePayload);
+ RM_VERIFY_SUCCESS(result, OC_STACK_OK);
}
if ( 0 >= u_linklist_length(updatedTableList))
{
- OC_LOG_V(DEBUG, TAG, "No updation is needed, Length is %d", u_linklist_length(updatedTableList));
+ OC_LOG_V(DEBUG, TAG, "No updation is needed, Length is %d",
+ u_linklist_length(updatedTableList));
goto exit;
}
sendNotification:
result = RMSendNotificationToAll(updatedPayload);
RM_VERIFY_SUCCESS(result, OC_STACK_OK);
- RMPFreePayload(updatedPayload);
exit:
+ RMPFreePayload(updatedPayload);
+ RTMFreeGatewayRouteTable(&gatewayTableList);
u_linklist_free(&updatedTableList);
- u_linklist_free(&gatewayTableList);
u_linklist_free(&alternativeRouteList);
OC_LOG(DEBUG, TAG, "RMHandleResponsePayload OUT");
return OC_STACK_OK;
if (OC_STACK_OK != result)
{
OC_LOG_V(DEBUG, TAG, "Send response failed[%d]", result);
+ RMPFreePayload(payload);
return result;
}
RMPFreePayload(payload);
-
// Send a observe request
result = RMSendObserveRequest(&(request->devAddr), NULL);
if (OC_STACK_OK != result)
result = RMPConstructObserveResPayload(g_GatewayID, g_sequenceNumber,
g_routingGatewayTable, true,
&payload);
- RM_VERIFY_SUCCESS(result, OC_STACK_OK);
+ if (OC_STACK_OK != result)
+ {
+ OC_LOG_V(ERROR, TAG, "RMPConstructObserveResPayload failed[%d]", result);
+ RMPFreePayload(payload);
+ goto exit;
+ }
result = RMSendResponse(request, resource, payload);
- RM_VERIFY_SUCCESS(result, OC_STACK_OK);
RMPFreePayload(payload);
+ RM_VERIFY_SUCCESS(result, OC_STACK_OK);
exit:
OC_LOG(DEBUG, TAG, "RMHandleOBSERVERequest OUT");
return result;
g_sequenceNumber++;
result = RMPConstructRemovalPayload(g_GatewayID, g_sequenceNumber, removedGatewayNodes,
false, &resPayloads);
- RTMFreeGatewayRouteTable(&removedGatewayNodes);
- RM_VERIFY_SUCCESS(result, OC_STACK_OK);
+ if (OC_STACK_OK != result)
+ {
+ OC_LOG_V(ERROR, TAG, "RMPConstructRemovalPayload failed[%d]", result);
+ RMPFreePayload(resPayloads);
+ goto exit;
+ }
result = RMSendNotificationToAll(resPayloads);
+ RMPFreePayload(resPayloads);
RM_VERIFY_SUCCESS(result, OC_STACK_OK);
RTMPrintTable(g_routingGatewayTable, g_routingEndpointTable);
}
exit:
+ RTMFreeGatewayRouteTable(&removedGatewayNodes);
OC_LOG(DEBUG, TAG, "RMHandleDELETERequest OUT");
return result;
}
OCRepPayload *payload = NULL;
result = RMPConstructObserveResPayload(g_GatewayID, g_sequenceNumber, NULL,
false, &payload);
- RM_VERIFY_SUCCESS(result, OC_STACK_OK);
-
+ if (OC_STACK_OK != result)
+ {
+ OC_LOG_V(ERROR, TAG, "RMPConstructObserveResPayload failed[%d]", result);
+ RMPFreePayload(payload);
+ goto exit;
+ }
OC_LOG(DEBUG, TAG, "Sending the alive notification to all");
// Send notification for every 15s to all the neighbours.
result = RMSendNotificationToAll(payload);
+ RMPFreePayload(payload);
RM_VERIFY_SUCCESS(result, OC_STACK_OK);
}
result = RMPConstructRemovalPayload(g_GatewayID, g_sequenceNumber, removedEntries,
false, &resPayloads);
RTMFreeGatewayRouteTable(&removedEntries);
- RM_VERIFY_SUCCESS(result, OC_STACK_OK);
+ if (OC_STACK_OK != result)
+ {
+ OC_LOG_V(ERROR, TAG, "RMPConstructRemovalPayload failed[%d]", result);
+ RMPFreePayload(resPayloads);
+ goto exit;
+ }
result = RMSendNotificationToAll(resPayloads);
+ RMPFreePayload(resPayloads);
RM_VERIFY_SUCCESS(result, OC_STACK_OK);
RTMPrintTable(g_routingGatewayTable, g_routingEndpointTable);
}
g_refreshTableTime = currentTime;
g_isValidated = false;
+ u_linklist_free(&removedEntries);
goto exit;
}
if (OC_STACK_OK != result)
{
OC_LOG_V(DEBUG, TAG, "RMPConstructGatewayPayload failed[%d]", result);
+ RMPFreePayload(payload);
u_linklist_free(&neighbourNodes);
return;
}
for (uint32_t i = 0; i < u_arraylist_length(entry->destination->destIntfAddr); i++)
{
RTMDestIntfInfo_t *dest = u_arraylist_get(entry->destination->destIntfAddr, i);
+ if (!dest)
+ {
+ OC_LOG(ERROR, RM_TAG, "Failed to get dest address");
+ continue;
+ }
OCDevAddr devAddr = {.adapter = OC_DEFAULT_ADAPTER};
CopyEndpointToDevAddr(&(dest->destIntfAddr), &devAddr);
OC_LOG_V(DEBUG, TAG, "\nDestination interface addresses: %s[%d], OCDevAddr: %s[%d]",
RMSendDeleteRequest(&devAddr, payload);
}
}
+
u_linklist_get_next(&iterTable);
}
if (NULL == *gatewayTable)
{
*gatewayTable = u_linklist_create();
+ if (NULL == *gatewayTable)
+ {
+ OC_LOG(ERROR, TAG, "u_linklist_create failed");
+ return OC_STACK_NO_MEMORY;
+ }
}
if (1 == routeCost && 0 != nextHop)
if (NULL == *endpointTable)
{
*endpointTable = u_linklist_create();
+ if (NULL == *endpointTable)
+ {
+ OC_LOG(ERROR, TAG, "u_linklist_create failed");
+ return OC_STACK_NO_MEMORY;
+ }
}
u_linklist_iterator_t *iterTable = NULL;
if (NULL == *removedGatewayNodes)
{
*removedGatewayNodes = u_linklist_create();
+ if (NULL == *removedGatewayNodes)
+ {
+ OC_LOG(ERROR, TAG, "u_linklist_create failed");
+ return OC_STACK_NO_MEMORY;
+ }
}
OCStackResult ret = OC_STACK_OK;
u_linklist_init_iterator(*gatewayTable, &iterTable);
for (uint32_t i = 0; i < u_arraylist_length(entry->destination->destIntfAddr); i++)
{
RTMDestIntfInfo_t *destCheck = u_arraylist_get(entry->destination->destIntfAddr, i);
+ if(!destCheck)
+ {
+ continue;
+ }
if (0 == memcmp(destCheck->destIntfAddr.addr, destInfAdr->destIntfAddr.addr,
strlen(destInfAdr->destIntfAddr.addr))
&& destInfAdr->destIntfAddr.port == destCheck->destIntfAddr.port)
RM_NULL_CHECK_VOID(gatewayTable, TAG, "gatewayTable");
*neighbourNodes = u_linklist_create();
+ if (NULL == *neighbourNodes)
+ {
+ OC_LOG(ERROR, TAG, "u_linklist_create failed");
+ return;
+ }
u_linklist_iterator_t *iterTable = NULL;
u_linklist_init_iterator(gatewayTable, &iterTable);
while (NULL != iterTable)
while (NULL != iterTable)
{
RTMGatewayEntry_t *entry = u_linklist_get_data(iterTable);
- for (uint32_t i = 0; i < u_arraylist_length(entry->destination->destIntfAddr); i++)
+ if (0 < u_arraylist_length(entry->destination->destIntfAddr))
{
- RTMDestIntfInfo_t *destCheck = u_arraylist_get(entry->destination->destIntfAddr, i);
+ RTMDestIntfInfo_t *destCheck = u_arraylist_get(entry->destination->destIntfAddr, 0);
if (NULL == destCheck)
{
OC_LOG(ERROR, TAG, "destCheck is null");
*obsList = (OCObservationId *) OICRealloc((void *)*obsList,
(sizeof(OCObservationId) * (len + 1)));
}
- break;
}
u_linklist_get_next(&iterTable);
}
{
RTMDestIntfInfo_t *removeAdr =
u_arraylist_get(entry->destination->destIntfAddr, i);
+ if (!removeAdr)
+ {
+ continue;
+ }
if (0 == memcmp(removeAdr->destIntfAddr.addr, destInterfaces.destIntfAddr.addr,
strlen(destInterfaces.destIntfAddr.addr))
&& destInterfaces.destIntfAddr.port == removeAdr->destIntfAddr.port)
RM_NULL_CHECK_WITH_RET(*gatewayTable, TAG, "*gatewayTable");
*invalidTable = u_linklist_create();
+ if (NULL == *invalidTable)
+ {
+ OC_LOG(ERROR, TAG, "u_linklist_create failed");
+ return OC_STACK_NO_MEMORY;
+ }
+
u_linklist_iterator_t *iterTable = NULL;
uint64_t presentTime = RTMGetCurrentTime();
for (uint32_t i = 0; i < u_arraylist_length(entry->destination->destIntfAddr); i++)
{
RTMDestIntfInfo_t *destCheck = u_arraylist_get(entry->destination->destIntfAddr, i);
+ if (!destCheck)
+ {
+ continue;
+ }
if (GATEWAY_ALIVE_TIMEOUT < (presentTime - destCheck->timeElapsed))
{
destCheck->isValid = false;
RM_NULL_CHECK_WITH_RET(*gatewayTable, TAG, "*gatewayTable");
*invalidTable = u_linklist_create();
+ if (NULL == *invalidTable)
+ {
+ OC_LOG(ERROR, TAG, "u_linklist_create failed");
+ return OC_STACK_NO_MEMORY;
+ }
u_linklist_iterator_t *iterTable = NULL;
u_linklist_init_iterator(*gatewayTable, &iterTable);
for (uint32_t i = 0; i < u_arraylist_length(entry->destination->destIntfAddr); i++)
{
RTMDestIntfInfo_t *destCheck = u_arraylist_get(entry->destination->destIntfAddr, i);
- if (!destCheck->isValid)
+ if (!destCheck && !destCheck->isValid)
{
void *data = u_arraylist_remove(entry->destination->destIntfAddr, i);
OICFree(data);