* the consumer. A NULL handle is permitted in the event where the caller
* has no use for the return value.
* @param remoteAddr The target device address to discovery a resource.
- * @param payload Encoded request payload.
+ * @param payload Encoded request payload.This API takes ownership of payload passed as input,
+ * so whenever it returns, payload memory is de-allocated.
* @param cbData Asynchronous callback function that is invoked by the stack when
* discovery or resource interaction is received. The discovery could be
* related to filtered/scoped/particular resource. The callback is
#define VERIFY_NON_NULL_V(arg) { if (!arg) {OIC_LOG_V(FATAL, TAG, "%s is NULL", #arg);\
goto exit;} }
+#define VERIFY_NON_NULL_EXIT(arg, logLevel, retVal) { if (!(arg)) { OIC_LOG((logLevel), \
+ TAG, #arg " is NULL"); ret = retVal; goto exit; } }
+
/**
* The KeepAlive table entries are removed
* if it can't receive response message within 60 seconds.
OCStackResult OCSendKeepAliveRequest(OCDoHandle *handle, const char *remoteAddr,
OCPayload *payload, OCCallbackData *cbData)
{
- VERIFY_NON_NULL(remoteAddr, FATAL, OC_STACK_INVALID_PARAM);
- VERIFY_NON_NULL(cbData, FATAL, OC_STACK_INVALID_PARAM);
- VERIFY_NON_NULL(cbData->cb, FATAL, OC_STACK_INVALID_CALLBACK);
- VERIFY_NON_NULL(payload, FATAL, OC_STACK_INVALID_CALLBACK);
+ OCStackResult ret;
+ VERIFY_NON_NULL_EXIT(remoteAddr, FATAL, OC_STACK_INVALID_PARAM);
+ VERIFY_NON_NULL_EXIT(cbData, FATAL, OC_STACK_INVALID_PARAM);
+ VERIFY_NON_NULL_EXIT(cbData->cb, FATAL, OC_STACK_INVALID_CALLBACK);
+ VERIFY_NON_NULL_EXIT(payload, FATAL, OC_STACK_INVALID_CALLBACK);
OIC_LOG(DEBUG, TAG, "SendKeepAliveRequest IN");
if (result != OC_STACK_OK)
{
OIC_LOG_V(DEBUG, TAG, "Unable to parse uri: %s", remoteAddr);
+ OCPayloadDestroy(payload);
return OC_STACK_ERROR;
}
- VERIFY_NON_NULL(devAddr, FATAL, OC_STACK_INVALID_PARAM);
+ VERIFY_NON_NULL_EXIT(devAddr, FATAL, OC_STACK_INVALID_PARAM);
if (!(devAddr->adapter & OC_ADAPTER_TCP))
{
OIC_LOG_V(DEBUG, TAG, "Not supported connectivity type");
OICFree(devAddr);
+ OCPayloadDestroy(payload);
return OC_STACK_ERROR;
}
oc_mutex_unlock(g_mutexObjectList);
OIC_LOG(ERROR, TAG, "Failed to add new KeepAlive entry");
OICFree(devAddr);
+ OCPayloadDestroy(payload);
return OC_STACK_ERROR;
}
}
oc_mutex_unlock(g_mutexObjectList);
OIC_LOG(ERROR, TAG, "Already sent a ping request to remote device");
OICFree(devAddr);
+ OCPayloadDestroy(payload);
return OC_STACK_ERROR;
}
entry->interval = interval;
OIC_LOG(DEBUG, TAG, "SendKeepAliveRequest OUT");
OICFree(devAddr);
return result;
+
+exit:
+ OCPayloadDestroy(payload);
+ return (ret);
}
OCStackResult OCHandleKeepAliveResponse(const CAEndpoint_t *endPoint, const OCPayload *payload)