{
//copy URI
memcpy (&(serverRequest.resourceUrl), newUri, strlen(newUri));
+ OCFree(newUri);
}
else
{
OC_LOG(ERROR, TAG, PCF("URI length exceeds MAX_URI_LENGTH."));
+ OCFree(newUri);
+ OCFree(query);
return;
}
//copy query
if(query)
{
- if(strlen((char*)query) < MAX_QUERY_LENGTH)
+ if(strlen(query) < MAX_QUERY_LENGTH)
{
- memcpy (&(serverRequest.query), query, strlen((char*)query));
+ memcpy (&(serverRequest.query), query, strlen(query));
+ OCFree(query);
}
else
{
OC_LOG(ERROR, TAG, PCF("Query length exceeds MAX_QUERY_LENGTH."));
+ OCFree(query);
return;
}
}
{
OC_LOG(ERROR, TAG, PCF("HandleStackRequests failed"));
}
+ // requestToken is fed to HandleStackRequests, which then goes to AddServerRequest.
+ // The token is copied in there, and is thus still owned by this function.
+ OCFree(serverRequest.requestToken);
OC_LOG(INFO, TAG, PCF("Exit HandleCARequests"));
}
if(query)
{
result = getResourceType((char *) query, &resourceType);
+ OCFree(query);
if(resourceType)
{
OC_LOG_V(DEBUG, TAG, "Got Resource Type: %s", resourceType);
if (caResult != CA_STATUS_OK)
{
OC_LOG(ERROR, TAG, PCF("CAGenerateToken error"));
- CADestroyToken(token);
result = CAResultToOCResult(caResult);
goto exit;
}
OCFree(resHandle);
OCFree(requestUri);
OCFree(resourceType);
+ CADestroyToken(token);
}
CADestroyRemoteEndpoint(endpoint);
OCFree(grpEnd.resourceUri);
if (CreateObserveHeaderOption (&(requestData.options),
options, numOptions, OC_OBSERVE_DEREGISTER) != OC_STACK_OK)
{
+ CADestroyRemoteEndpoint(endpoint);
return OC_STACK_ERROR;
}
requestData.numOptions = numOptions + 1;
requestInfo.info = requestData;
caResult = CASendRequest(endpoint, &requestInfo);
+ CADestroyRemoteEndpoint(endpoint);
if (caResult != CA_STATUS_OK)
{
strncpy(addressInfo.IP.ipAddress, OC_MULTICAST_IP, CA_IPADDR_SIZE);
addressInfo.IP.port = OC_MULTICAST_PORT;
- //TODO make sure there is no memory leak here since another copy
- //of token is being created inside AddObserver
CAToken_t caToken = NULL;
CAResult_t caResult = CAGenerateToken(&caToken);
if (caResult != CA_STATUS_OK)
AddObserver(OC_PRESENCE_URI, NULL, 0, &caToken,
(OCResource *)presenceResource.handle, OC_LOW_QOS,
&addressInfo, connType);
+ CADestroyToken(caToken);
}
// Each time OCStartPresence is called