This commit included code cleanup.
1. coding idiom
2. double free.
3. warning.
4. unlock
second patch included
change the mutex_unlock in NSProviderInterface.
Change-Id: Iff615c577f0cb0e868fa29c1592c523c9bed4d6f
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9679
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
\r
case 4:\r
printf("NSRead");\r
- NSSyncInfo * sync = (NSSyncInfo*) OICMalloc(sizeof(NSSyncInfo));\r
-\r
- sync->messageId = OICStrdup("dev_001");\r
- sync->state = 1;\r
-\r
break;\r
\r
case 5:\r
printf("Session Code: ");\r
gets(REMOTE_SERVER_SESSION);\r
\r
-\r
NSCloudLogin(REMOTE_SERVER_ADDRESS, REMOTE_SERVER_SESSION, CloudLoginoutCallback);\r
printf("OCCloudLogin requested");\r
break;\r
#define NS_ATTRIBUTE_DATETIME "DATE_TIME"
#define NS_ATTRIBUTE_TTL "TTL"
-#include <stdint.h>
-
/**
* Result code of notification service
*/
{
NSSyncInfo * newMsg = NULL;
- if(copyMsg == NULL)
+ if(!copyMsg)
{
NS_LOG(ERROR, "Copy Msg is NULL");
return NULL;
newMsg = (NSSyncInfo *)OICMalloc(sizeof(NSSyncInfo));
+ if(!newMsg)
+ {
+ NS_LOG(ERROR, "newMsg is NULL");
+ return NULL;
+ }
+
newMsg->messageId = copyMsg->messageId;
OICStrcpy(newMsg->providerId, UUID_STRING_SIZE, copyMsg->providerId);
newMsg->state = copyMsg->state;
}
newMsg = (NSConsumer *)OICMalloc(sizeof(NSConsumer));
+
+ if(!newMsg)
+ {
+ NS_LOG(ERROR, "newMsg is NULL");
+ return NULL;
+ }
+
(newMsg->consumerId)[0] = '\0';
OICStrcpy(newMsg->consumerId, UUID_STRING_SIZE, copyMsg->consumerId);
{
NS_LOG(DEBUG, "NSGetSyncInfo - IN");
char * providerId = NULL;
- int64_t state;
+ int64_t state = 0;
if(!payload)
{
NSMediaContents * newObj = (NSMediaContents *)OICMalloc(sizeof(NSMediaContents));
+ if(!newObj)
+ {
+ NS_LOG(ERROR, "contents newObj is NULL");
+ return NULL;
+ }
+
if(copyObj->iconImage)
{
newObj->iconImage = OICStrdup(copyObj->iconImage);
{
if(!obj)
{
- return NS_OK;
+ return NS_FAIL;
}
NSFreeMalloc(&(obj->iconImage));
NSMessage * NSInitializeMessage()
{
NSMessage * msg = (NSMessage *)OICMalloc(sizeof(NSMessage));
+
+ if(!msg)
+ {
+ NS_LOG(ERROR, "Msg is NULL");
+ return NULL;
+ }
+
msg->messageId = OICGetCurrentTime(TIME_IN_MS);
(msg->providerId)[0] = '\0';
msg->type = 0;
if(!initProvider)\r
{\r
NS_LOG(DEBUG, "Provider service has not been started yet");\r
+ pthread_mutex_unlock(&nsInitMutex);\r
return NS_FAIL;\r
}\r
\r
return NS_ERROR;
}
- OCRepPayload* payload;
+ OCRepPayload* payload = NULL;
if (NSSetMessagePayload(msg, &payload) != NS_OK)
{
if (subData->isWhite)
{
if(subData->messageObId != 0)
+ {
obArray[obCount++] = subData->messageObId;
+ }
if(subData->remote_messageObId != 0)
+ {
obArray[obCount++] = subData->remote_messageObId;
+ }
}
it = it->next;
}
if (subData->isWhite)
{
if(subData->syncObId != 0)
+ {
obArray[obCount++] = subData->syncObId;
+ }
if(subData->remote_syncObId != 0)
+ {
obArray[obCount++] = subData->remote_syncObId;
+ }
}
it = it->next;
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "NSProviderResource.h"
+#include <string.h>
NSNotificationResource NotificationResource;
NSMessageResource NotificationMessageResource;
OCStackApplicationResult NSHandlePublishCb(void *ctx, OCDoHandle handle,
OCClientResponse *clientResponse)
{
+ (void) handle;
+
if (ctx != (void *)DEFAULT_CONTEXT_VALUE)
{
NS_LOG(DEBUG, "Invalid publish callback received");
void NSPushQueue(NSSchedulerType schedulerType, NSTaskType taskType, void* data)\r
{\r
\r
- if(NSIsRunning[schedulerType] == false)\r
+ if(!NSIsRunning[schedulerType])\r
+ {\r
return;\r
+ }\r
\r
pthread_mutex_lock(&NSMutex[schedulerType]);\r
\r
if (NSHeadMsg[schedulerType] == NULL)\r
{\r
NSHeadMsg[schedulerType] = (NSTask*) OICMalloc(sizeof(NSTask));\r
- memset(NSHeadMsg[schedulerType], 0, sizeof(NSTask));\r
NSHeadMsg[schedulerType]->taskType = taskType;\r
NSHeadMsg[schedulerType]->taskData = data;\r
NSHeadMsg[schedulerType]->nextTask = NULL;\r
else\r
{\r
NSTask* newNode = (NSTask*) OICMalloc(sizeof(NSTask));\r
- memset(newNode, 0, sizeof(NSTask));\r
newNode->taskType = taskType;\r
newNode->taskData = data;\r
newNode->nextTask = NULL;\r
NS_LOG(DEBUG, "NSSendAccessPolicyResponse - IN");\r
\r
// put notification resource\r
- OCResourceHandle notificationResourceHandle;\r
+ OCResourceHandle notificationResourceHandle = NULL;\r
if (NSPutNotificationResource(NSGetSubscriptionAccepter(), ¬ificationResourceHandle)\r
!= NS_OK)\r
{\r
return NS_ERROR;\r
}\r
\r
- OCResourceHandle rHandle;\r
+ OCResourceHandle rHandle = NULL;\r
if (NSPutMessageResource(NULL, &rHandle) != NS_OK)\r
{\r
NS_LOG(ERROR, "Fail to put notification resource");\r
providerInfo = (NSProviderInfo *) OICMalloc(sizeof(NSProviderInfo));\r
const char * generatedUuid = (char *)OCGetServerInstanceIDString();\r
NS_LOG_V(DEBUG, "Generate Provider ID: %s", generatedUuid);\r
- OICStrcpy(providerInfo->providerId, strlen(generatedUuid), generatedUuid);\r
+ OICStrcpy(providerInfo->providerId, UUID_STRING_SIZE, generatedUuid);\r
\r
providerInfo->providerName = NULL;\r
}\r
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
\r
#include "NSProviderMemoryCache.h"\r
+#include <string.h>\r
\r
NSCacheList * NSStorageCreate()\r
{\r
\r
NSCacheMsgData * msgData = (NSCacheMsgData *) newObj->data;\r
\r
+ pthread_mutex_unlock(&NSCacheMutex);\r
NSCacheElement * it = NSStorageRead(list, msgData->id);\r
+ pthread_mutex_lock(&NSCacheMutex);\r
if (it)\r
{\r
NSCacheMsgData * itData = (NSCacheMsgData *) it->data;\r
if (del == list->head) // first object\r
{\r
if (del == list->tail) // first object (one object)\r
+ {\r
list->tail = del->next;\r
+ }\r
\r
list->head = del->next;\r
\r
if (NSProviderCompareIdCacheData(type, del->data, delId))\r
{\r
if (del == list->tail) // delete object same to last object\r
+ {\r
list->tail = prev;\r
+ }\r
\r
prev->next = del->next;\r
NSProviderDeleteCacheData(type, del->data);\r
{\r
if (id == data->messageObId || id == data->syncObId || id == data->remote_messageObId ||\r
id == data->remote_syncObId)\r
+ {\r
return true;\r
+ }\r
+\r
return false;\r
}\r
\r
if (del == list->head) // first object\r
{\r
if (del == list->tail) // first object (one object)\r
+ {\r
list->tail = del->next;\r
+ }\r
\r
list->head = del->next;\r
\r
if (NSIsSameObId(curr, id))\r
{\r
if (del == list->tail) // delete object same to last object\r
+ {\r
list->tail = prev;\r
+ }\r
\r
prev->next = del->next;\r
NSProviderDeleteCacheData(type, del->data);\r
\r
#include <pthread.h>\r
#include <stdbool.h>\r
-#include <string.h>\r
\r
#include "NSCommon.h"\r
#include "NSConstants.h"\r