1. definitely losted memory was deallocated.
2. pthread creating type was modified for parameter deallocation.
3. invalid c-string copy was fixed.
Change-Id: Iab32535f164029ccd8a82d49968ce0a44e8b8bd1
Signed-off-by: KIM JungYong <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13169
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
if (setValue == false)
{
pthread_mutex_destroy(*NSGetStackMutex());
+ NSOICFree(*NSGetStackMutex());
*NSGetStackMutex() = NULL;
NSOICFree(*NSGetConsumerId());
data->state = response;
NSConsumerThread * thread = NSThreadInit(NSProviderChangedFunc, (void *) data);
- NS_VERIFY_NOT_NULL_V(thread);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(thread,
+ {
+ NSRemoveProvider(retProvider);
+ NSOICFree(data);
+ });
NSDestroyThreadHandle(thread);
+ NSOICFree(thread);
}
NSSyncInfoReceivedCallback * NSGetBoneNotificationSyncCb()
NS_VERIFY_NOT_NULL_V(thread);
NSDestroyThreadHandle(thread);
+ NSOICFree(thread);
}
NSMessageReceivedCallback * NSGetBoneMessagePostedCb()
NS_VERIFY_NOT_NULL_V(thread);
NSDestroyThreadHandle(thread);
+ NSOICFree(thread);
}
NSTask * NSMakeTask(NSTaskType type, void * data)
NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(
newMsg->mediaContents, NULL, NSRemoveMessage(newMsg));
newMsg->mediaContents->iconImage =
- (char *)OICMalloc(sizeof(char)*strlen(msg->mediaContents->iconImage));
+ (char *)OICMalloc(sizeof(char)*strlen(msg->mediaContents->iconImage) + 1);
NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(
newMsg->mediaContents->iconImage, NULL, NSRemoveMessage(newMsg));
memcpy(newMsg->mediaContents->iconImage, msg->mediaContents->iconImage,
- strlen(msg->mediaContents->iconImage));
+ strlen(msg->mediaContents->iconImage) + 1);
}
newMsg->extraInfo = NULL;
tmp->messageHandle = NULL;
tmp->syncHandle = NULL;
NSOICFree(tmp->addr);
- tmp = tmp->next;
+ NSProviderConnectionInfo * next = tmp->next;
+ NSOICFree(tmp);
+ tmp = next;
}
-
- NSOICFree(connections);
}
NSProviderConnectionInfo * NSCreateProviderConnections(OCDevAddr * inAddr)
{
NS_VERIFY_NOT_NULL_V(data);
- NSProvider_internal * prov = data;
+ NSProvider_internal * prov = (NSProvider_internal *) data;
NSOICFree(prov->messageUri);
NSOICFree(prov->syncUri);
int mutexRet = pthread_mutex_lock(*(NSGetStackMutex()));
NS_VERIFY_NOT_NULL(mutexRet != 0 ? NULL : (void *)1, OC_STACK_ERROR);
- OCCallbackData cbdata = { 0, };
+ OCCallbackData cbdata = { NULL, NULL, NULL };
cbdata.cb = callbackFunc;
cbdata.context = callbackData;
NS_LOG(DEBUG, "get state");
int64_t state = 0;
getResult = OCRepPayloadGetPropInt(payload, NS_ATTRIBUTE_STATE, & state);
- NS_VERIFY_NOT_NULL(getResult == true ? (void *) 1 : NULL, NULL);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(getResult == true ? (void *) 1 : NULL,
+ NULL, NSOICFree(pId));
NS_LOG(DEBUG, "create NSSyncInfo");
NSSyncInfo * retSync = NSCreateSyncInfo_consumer(id, pId, (NSSyncType)state);
+ NSOICFree(pId);
NS_VERIFY_NOT_NULL(retSync, NULL);
NS_LOG_V(DEBUG, "Sync ID : %lld", (long long int)retSync->messageId);
NS_VERIFY_NOT_NULL_V(task->taskData);
NS_LOG(DEBUG, "Request Subscribe");
NSResult ret = NSConsumerSubscribeProvider((NSProvider *)task->taskData);
+ NSRemoveProvider_internal((void *) task->taskData);
NS_VERIFY_NOT_NULL_V(ret == NS_OK ? (void *)1 : NULL);
}
else if (task->taskType == TASK_SEND_SYNCINFO)
{
- NS_VERIFY_NOT_NULL_V(task->taskData);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(task->taskData, NSOICFree(task));
NSSyncInfo_internal * syncInfo = (NSSyncInfo_internal *)task->taskData;
NSProviderConnectionInfo * info = syncInfo->connection;
else if (task->taskType == TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL)
{
NSProvider_internal * provider = (NSProvider_internal *)task->taskData;
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(provider,
+ {
+ NSRemoveProvider_internal(provider);
+ NSOICFree(task);
+ });
NSProviderConnectionInfo * connections = provider->connection;
while(connections)
else if (task->taskType == TASK_CONSUMER_REQ_TOPIC_LIST)
{
NSProvider_internal * provider = NSCopyProvider_internal(task->taskData);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(provider,
+ {
+ NSRemoveProvider_internal((void *) task->taskData);
+ NSOICFree(task);
+ });
NSRemoveProvider_internal((NSProvider_internal *)task->taskData);
NSProviderConnectionInfo * connections = provider->connection;
- NS_VERIFY_NOT_NULL_V(connections);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(connections,
+ {
+ NSRemoveProvider_internal((void *) provider);
+ NSRemoveProvider_internal((void *) task->taskData);
+ NSOICFree(task);
+ });
char * topicUri = OICStrdup(provider->topicUri);
- NS_VERIFY_NOT_NULL_V(topicUri);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(topicUri,
+ {
+ NSRemoveProvider_internal((void *) provider);
+ NSRemoveProvider_internal((void *) task->taskData);
+ NSOICFree(task);
+ });
OCConnectivityType type = CT_DEFAULT;
if (connections->addr->adapter == OC_ADAPTER_TCP)
NS_LOG(DEBUG, "get topic query");
char * query = NSMakeRequestUriWithConsumerId(topicUri);
-
- NS_VERIFY_NOT_NULL_V(query);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(query,
+ {
+ NSRemoveProvider_internal((void *) provider);
+ NSRemoveProvider_internal((void *) task->taskData);
+ NSOICFree(task);
+ });
NS_LOG_V(DEBUG, "topic query : %s", query);
OCStackResult ret = NSInvokeRequest(NULL, OC_REST_GET, connections->addr,
query, NULL, NSIntrospectTopic, (void *) provider,
NSRemoveProvider_internal, type);
- NS_VERIFY_STACK_SUCCESS_V(NSOCResultToSuccess(ret));
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(NSOCResultToSuccess(ret) == true ? (void *) 1 : NULL,
+ {
+ NSRemoveProvider_internal((void *) provider);
+ NSRemoveProvider_internal((void *) task->taskData);
+ NSOICFree(task);
+ });
NSOICFree(query);
NSOICFree(topicUri);
else if (task->taskType == TASK_CONSUMER_SELECT_TOPIC_LIST)
{
NSProvider_internal * provider = (NSProvider_internal *)task->taskData;
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(provider,
+ {
+ NSRemoveProvider_internal(provider);
+ NSOICFree(task);
+ });
NSProviderConnectionInfo * connections = provider->connection;
- NS_VERIFY_NOT_NULL_V(connections);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(connections,
+ {
+ NSRemoveProvider_internal(provider);
+ NSOICFree(task);
+ });
OCRepPayload * payload = OCRepPayloadCreate();
- NS_VERIFY_NOT_NULL_V(payload);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(payload,
+ {
+ NSRemoveProvider_internal(provider);
+ NSOICFree(task);
+ });
NSTopicLL * topicLL = provider->topicLL;
NSTopicLL * iter = topicLL;
if (topicLLSize > 0)
{
topicPayload = (OCRepPayload **) OICMalloc(sizeof(OCRepPayload *)*topicLLSize);
- NS_VERIFY_NOT_NULL_V(topicPayload);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(topicPayload,
+ {
+ OCRepPayloadDestroy(payload);
+ NSRemoveProvider_internal(provider);
+ NSOICFree(task);
+ });
while (iter || iterSize < topicLLSize)
{
}
char * topicUri = OICStrdup(provider->topicUri);
- NS_VERIFY_NOT_NULL_V(topicUri);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(topicUri,
+ {
+ OCRepPayloadDestroy(payload);
+ NSRemoveProvider_internal(provider);
+ NSOICFree(task);
+ });
OCConnectivityType type = CT_DEFAULT;
if (connections->addr->adapter == OC_ADAPTER_TCP)
NS_LOG(DEBUG, "get topic query");
char * query = NULL;
query = NSMakeRequestUriWithConsumerId(topicUri);
- NS_VERIFY_NOT_NULL_V(query);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(query,
+ {
+ NSOICFree(topicUri);
+ OCRepPayloadDestroy(payload);
+ NSRemoveProvider_internal(provider);
+ NSOICFree(task);
+ });
NS_LOG_V(DEBUG, "topic query : %s", query);
OCStackResult ret = NSInvokeRequest(NULL, OC_REST_POST, connections->addr,
query, (OCPayload*)payload, NSConsumerCheckPostResult,
NULL, NULL, type);
- NS_VERIFY_STACK_SUCCESS_V(NSOCResultToSuccess(ret));
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(
+ NSOCResultToSuccess(ret) == true ? (void *) 1 : NULL,
+ {
+ NSOICFree(query);
+ NSOICFree(topicUri);
+ NSRemoveProvider_internal(provider);
+ NSOICFree(task);
+ });
NSRemoveProvider_internal(provider);
NSOICFree(query);
NS_VERIFY_NOT_NULL(clientResponse, OC_STACK_KEEP_TRANSACTION);
NS_VERIFY_STACK_SUCCESS(NSOCResultToSuccess(clientResponse->result),
- OC_STACK_KEEP_TRANSACTION);
+ OC_STACK_KEEP_TRANSACTION)
NS_LOG_V(DEBUG, "GET response income : %s:%d",
clientResponse->devAddr.addr, clientResponse->devAddr.port);
NSTopicLL * newTopicLL = NSGetTopicLL(clientResponse);
NSProvider_internal * provider = NSCopyProvider_internal((NSProvider_internal *) ctx);
+ NS_VERIFY_NOT_NULL(provider, OC_STACK_KEEP_TRANSACTION);
+ NSRemoveTopicLL(provider->topicLL);
provider->topicLL = NSCopyTopicLL(newTopicLL);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(provider->topicLL, OC_STACK_KEEP_TRANSACTION,
+ NSRemoveProvider_internal((void *) provider));
NS_LOG(DEBUG, "build NSTask");
NSTask * task = NSMakeTask(TASK_CONSUMER_RECV_TOPIC_LIST, (void *) provider);
NSDestroyMessageStateList();
pthread_mutex_destroy(*NSGetMessageListMutex());
- *NSGetMessageListMutex() = NULL;
+ NSOICFree(*NSGetMessageListMutex());
}
NSProvider_internal * NSProviderCacheFind(const char * providerId)
NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(ret == NS_OK ? (void *) 1 : NULL,
NS_ERROR, NSOICFree(obj));
+ NSOICFree(obj);
+
return NS_OK;
}
NSSetProviderCacheList(ProviderCache);
}
- NSCacheElement * obj = NULL;
- while ((obj = NSPopProviderCacheList(ProviderCache)))
+ NSCacheElement * obj = NSPopProviderCacheList(ProviderCache);
+ while (obj)
{
NS_LOG(DEBUG, "build NSTask");
NSProvider * prov = NSCopyProvider((NSProvider_internal *) obj->data);
NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(prov,
- NSRemoveProvider_internal((NSProvider_internal *) obj->data));
+ NSRemoveProvider_internal((void *) obj->data));
NSTask * task = NSMakeTask(TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL, prov);
NS_VERIFY_NOT_NULL_V(task);
NSConsumerPushEvent(task);
+ NSRemoveProvider_internal((void *) obj->data);
+ NSOICFree(obj);
+
+ obj = NSPopProviderCacheList(ProviderCache);
}
}
}
NSResult ret = NSProviderCacheUpdate(provider);
- NS_VERIFY_NOT_NULL_V(ret == NS_OK ? (void *) 1 : NULL);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(ret == NS_OK ? (void *) 1 : NULL,
+ NSRemoveProvider_internal(providerCacheData));
if (isAdded == false)
{
if (provider->accessPolicy == NS_SELECTION_CONSUMER && isSubscribing == false)
{
NS_LOG(DEBUG, "accepter is NS_ACCEPTER_CONSUMER, Callback to user");
- NSProvider * providerForCb = NSCopyProvider(provider);
- NSProviderChanged(providerForCb, NS_DISCOVERED);
- NSRemoveProvider(providerForCb);
+ NSProvider * prov = NSCopyProvider(provider);
+ NSProviderChanged(prov, NS_DISCOVERED);
+ NSRemoveProvider(prov);
}
else
{
NS_LOG(DEBUG, "accepter is NS_ACCEPTER_PROVIDER, request subscribe");
- NSProvider_internal * subProvider = NSCopyProvider_internal(provider);
+ NSProvider * subProvider = NSCopyProvider(provider);
NSTask * task = NSMakeTask(TASK_CONSUMER_REQ_SUBSCRIBE, (void *) subProvider);
- NS_VERIFY_NOT_NULL_V(task);
+ NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(task,
+ NSRemoveProvider_internal(providerCacheData));
NSConsumerPushEvent(task);
}
NS_VERIFY_NOT_NULL_V(ret == NS_OK ? (void *)1 : NULL);
NS_LOG_V(DEBUG, "Stopped Provider : %s", provider->providerId);
- NSProvider * providerForCb = NSCopyProvider(provider);
- NSProviderChanged(providerForCb, NS_STOPPED);
+ NSProvider * prov = NSCopyProvider(provider);
+ NSProviderChanged(prov, NS_STOPPED);
+ NSRemoveProvider(prov);
}
void NSConsumerHandleSubscribeSucceed(NSProvider_internal * provider)
pthread_mutex_unlock(mutex);
NSProviderChanged(prov, (NSProviderState) msg->messageId);
+ NSRemoveProvider(prov);
}
void NSConsumerHandleRecvMessage(NSMessage * msg)
NS_VERIFY_NOT_NULL_V (provider);
NSProviderConnectionInfo * connections = NSCopyProviderConnections(provider->connection);
- NSRemoveProvider_internal(provider);
+ NSRemoveProvider_internal((void *) provider);
NS_VERIFY_NOT_NULL_V (connections);
NSSyncInfo_internal * syncInfo = (NSSyncInfo_internal *)OICMalloc(sizeof(NSSyncInfo_internal));
NS_LOG(DEBUG, "call back to user");
NSProvider * prov = NSCopyProvider(provider);
NSProviderChanged((NSProvider *) prov, (NSProviderState) NS_TOPIC);
+ NSRemoveProvider(prov);
}
void NSConsumerInternalTaskProcessing(NSTask * task)
{
NS_LOG(DEBUG, "Receive Subscribe succeed from provider.");
NSConsumerHandleSubscribeSucceed((NSProvider_internal *)task->taskData);
- NSRemoveProvider_internal((NSProvider_internal *)task->taskData);
+ NSRemoveProvider_internal((void *)task->taskData);
break;
}
case TASK_CONSUMER_RECV_PROVIDER_CHANGED:
pthread_mutex_unlock(*NSGetMessageListMutex());
}
-NSMessageStateList * NSGetMessageStateList()
+NSMessageStateList ** NSGetMessageStateListAddr()
{
static NSMessageStateList * g_messageStateList = NULL;
if (g_messageStateList == NULL)
g_messageStateList->tail = NULL;
}
- return g_messageStateList;
+ return & g_messageStateList;
+}
+
+NSMessageStateList * NSGetMessageStateList()
+{
+ return * NSGetMessageStateListAddr();
}
NSMessageStateLL * NSFindMessageState(uint64_t msgId)
NSGetMessageStateList()->tail = NULL;
NSUnlockMessageListMutex();
+
+ pthread_mutex_t * mu = *NSGetMessageListMutex();
+ pthread_mutex_destroy(mu);
+ NSOICFree(mu);
+ *NSGetMessageListMutex() = NULL;
+
+ NSMessageStateList * list = NSGetMessageStateList();
+ NSOICFree(list);
+ *NSGetMessageStateListAddr() = NULL;
}
if (type == NS_CONSUMER_CACHE_PROVIDER)
{
- NSRemoveProvider_internal((NSProvider_internal *) del->data);
+ NSRemoveProvider_internal((void *) del->data);
}
NSOICFree(del);
pthread_mutex_unlock(mutex);
{
next = (NSCacheElement *) iter->next;
- NSRemoveProvider_internal((NSProvider_internal *) iter->data);
+ NSRemoveProvider_internal((void *) iter->data);
NSOICFree(iter);
iter = next;
NSConsumerQueueObject * node = NSPopQueue(queue);
while(node)
{
- NSConsumerQueueObject * next = (NSConsumerQueueObject *)node->next;
NSOICFree(node->data);
NSOICFree(node);
- node = next;
+ node = NSPopQueue(queue);
}
-
- NSOICFree(queue);
}
bool NSPushConsumerQueue(NSConsumerQueue * queue, NSConsumerQueueObject * object)
ret = NSConsumerSystemInit();
NS_VERIFY_NOT_NULL(ret == NS_OK ? (void *) 1 : NULL, NS_ERROR);
- NS_LOG(DEBUG, "queue thread init");
- handle = NSThreadInit(NSConsumerMsgHandleThreadFunc, NULL);
- NS_VERIFY_NOT_NULL(handle, NS_ERROR);
- NSSetMsgHandleThreadHandle(handle);
-
NS_LOG(DEBUG, "create queue");
queue = NSCreateQueue();
NS_VERIFY_NOT_NULL(queue, NS_ERROR);
NSSetMsgHandleQueue(queue);
+ NS_LOG(DEBUG, "queue thread init");
+ handle = NSThreadInit(NSConsumerMsgHandleThreadFunc, NULL);
+ NS_VERIFY_NOT_NULL(handle, NS_ERROR);
+ NSSetMsgHandleThreadHandle(handle);
+
return NS_OK;
}
NS_VERIFY_NOT_NULL(thread, NS_ERROR);
NSDestroyThreadHandle(thread);
+ NSOICFree(thread);
return NS_OK;
}
NSConsumerListenerTermiate();
NSCancelAllSubscription();
- NSThreadStop(*(NSGetMsgHandleThreadHandle()));
+ NSConsumerThread * thread = *(NSGetMsgHandleThreadHandle());
+ NSThreadStop(thread);
NSSetMsgHandleThreadHandle(NULL);
- NSDestroyQueue(*(NSGetMsgHandleQueue()));
+ NSConsumerQueue * queue = *(NSGetMsgHandleQueue());
+ NSDestroyQueue(queue);
NSSetMsgHandleQueue(NULL);
NSDestroyInternalCachedList();
if (obj)
{
NSConsumerTaskProcessing((NSTask *)(obj->data));
+ NSOICFree(obj);
}
NSThreadUnlock(queueHandleThread);
void * NSConsumerMsgPushThreadFunc(void * data)
{
- NSThreadDetach();
-
NSConsumerQueueObject * obj = NULL;
NSConsumerQueue * queue = NULL;
{
NSTask * getTopicTask = (NSTask *)OICMalloc(sizeof(NSTask));
NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(getTopicTask,
- NSRemoveProvider_internal((NSProvider_internal *) task->taskData));
+ NSRemoveProvider_internal((void *) task->taskData));
getTopicTask->nextTask = NULL;
getTopicTask->taskData =
(void *) NSCopyProvider_internal((NSProvider_internal *) task->taskData);
handle->isStarted = true;
- pthreadResult = pthread_create(&(handle->thread_id), NULL, func,
+ pthread_attr_t attrDetached;
+ pthread_attr_init(& attrDetached);
+ pthread_attr_setdetachstate(& attrDetached, PTHREAD_CREATE_DETACHED);
+
+ pthreadResult = pthread_create(&(handle->thread_id), & attrDetached, func,
(data == NULL) ? (void *) handle : (void *)data);
NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(pthreadResult == 0 ? (void *)1 : NULL,
NULL, NSDestroyThreadHandle(handle));
+ pthread_attr_destroy(& attrDetached);
+
pthread_mutex_unlock(&g_create_mutex);
return handle;
if (handle->thread_id)
{
- pthread_join(handle->thread_id, NULL);
+ void * retData = NULL;
+ pthread_join(handle->thread_id, & retData);
+ NSOICFree(retData);
}
}
pthread_mutex_destroy(&(handle->mutex));
pthread_mutexattr_destroy(&(handle->mutex_attr));
- NSOICFree(handle);
-
pthread_mutex_unlock(&g_create_mutex);
}