From: jaesick.shin Date: Fri, 14 Oct 2016 02:52:25 +0000 (+0900) Subject: bug fix about memory leak. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5ea98fab3650521bef841ddc950442575768d7e3;p=contrib%2Fiotivity.git bug fix about memory leak. this patch include, bug fix for dynamic analyzer. Change-Id: I4fc7ff7436ac6019abe3aaaf8467392068e0ad7d Signed-off-by: jaesick.shin Reviewed-on: https://gerrit.iotivity.org/gerrit/13253 Reviewed-by: Uze Choi Tested-by: jenkins-iotivity --- diff --git a/service/notification/src/provider/NSProviderMemoryCache.c b/service/notification/src/provider/NSProviderMemoryCache.c index 2e6034a..bcc0bfb 100644 --- a/service/notification/src/provider/NSProviderMemoryCache.c +++ b/service/notification/src/provider/NSProviderMemoryCache.c @@ -206,6 +206,7 @@ NSResult NSProviderStorageWrite(NSCacheList * list, NSCacheElement * newObj) NS_LOG(DEBUG, "already registered for topic name"); OICFree(topicData->topicName); OICFree(topicData); + OICFree(newObj); pthread_mutex_unlock(&NSCacheMutex); return NS_FAIL; } @@ -222,6 +223,7 @@ NSResult NSProviderStorageWrite(NSCacheList * list, NSCacheElement * newObj) NS_LOG(DEBUG, "already registered for topic name"); OICFree(topicData->topicName); OICFree(topicData); + OICFree(newObj); pthread_mutex_unlock(&NSCacheMutex); return NS_FAIL; } @@ -238,6 +240,7 @@ NSResult NSProviderStorageWrite(NSCacheList * list, NSCacheElement * newObj) NS_LOG(DEBUG, "already registered for topic name"); OICFree(topicData->topicName); OICFree(topicData); + OICFree(newObj); pthread_mutex_unlock(&NSCacheMutex); return NS_FAIL; } @@ -404,12 +407,14 @@ NSResult NSProviderDeleteCacheData(NSCacheType type, void * data) (int)topicData->state); OICFree(topicData->topicName); + OICFree(topicData); } else if(type == NS_PROVIDER_CACHE_CONSUMER_TOPIC_NAME || type == NS_PROVIDER_CACHE_CONSUMER_TOPIC_CID) { NSCacheTopicSubData * topicData = (NSCacheTopicSubData *) data; OICFree(topicData->topicName); + OICFree(topicData); } return NS_OK; diff --git a/service/notification/src/provider/NSProviderTopic.c b/service/notification/src/provider/NSProviderTopic.c index 36abe6d..bd23e91 100644 --- a/service/notification/src/provider/NSProviderTopic.c +++ b/service/notification/src/provider/NSProviderTopic.c @@ -307,12 +307,18 @@ NSResult NSSendTopicList(OCEntityHandlerRequest * entityHandlerRequest) (int) topics->state); NSTopicLL * next = topics->next; + OICFree(topics->topicName); OICFree(topics); topics = next; } OCRepPayloadSetPropObjectArray(payload, NS_ATTRIBUTE_TOPIC_LIST, (const OCRepPayload**) (payloadTopicArray), dimensions); + for (int i = 0; i < (int) dimensionSize; ++i) + { + OCRepPayloadDestroy(payloadTopicArray[i]); + } + OICFree(payloadTopicArray); } else { @@ -342,10 +348,11 @@ NSResult NSSendTopicList(OCEntityHandlerRequest * entityHandlerRequest) if (OCDoResponse(&response) != OC_STACK_OK) { NS_LOG(ERROR, "Fail to response topic list"); + OCRepPayloadDestroy(payload); return NS_ERROR; } - OCRepPayloadDestroy(payload); + OCRepPayloadDestroy(payload); NS_LOG(DEBUG, "NSSendTopicList - OUT"); return NS_OK; } @@ -465,14 +472,21 @@ void * NSTopicSchedule(void * ptr) { newObj->data = topicSyncResult->topicData; newObj->next = NULL; - NSProviderStorageWrite(consumerTopicList, newObj); - NSSendTopicUpdationToConsumer(subData->id); - topicSyncResult->result = NS_OK; + if(NSProviderStorageWrite(consumerTopicList, newObj) == NS_OK) + { + NSSendTopicUpdationToConsumer(subData->id); + topicSyncResult->result = NS_OK; + } + } + else + { + OICFree(subData->topicName); + OICFree(subData); + OICFree(newObj); } } pthread_cond_signal(topicSyncResult->condition); - pthread_mutex_unlock(topicSyncResult->mutex); - + pthread_mutex_unlock(topicSyncResult->mutex); } break; case TASK_UNSUBSCRIBE_TOPIC: