Fix defects detected by static code analyzer
authorJihun Ha <jihun.ha@samsung.com>
Thu, 23 Mar 2017 01:39:24 +0000 (10:39 +0900)
committerUze Choi <uzchoi@samsung.com>
Sat, 25 Mar 2017 05:00:47 +0000 (05:00 +0000)
Checking if a OICMalloc is failed is added.
Calling OICFree to prevent a memory leak is added.

Follow coding convention padding after condition "if ("

Change-Id: Ifdd2ba5f747758bd0120ff396f7441b77a444b81
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17971
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/easy-setup/enrollee/src/resourcehandler.c

index cdf27ed..8a1637f 100755 (executable)
@@ -70,33 +70,36 @@ bool CompareResourceInterface(char *from, char *iface)
     char *str = OICStrdup(from);
     char *ptr = strtok(str, ";");
 
-    if(ptr == NULL)
+    if (ptr == NULL)
     {
+        OICFree(str);
         return false;
     }
 
     do
     {
-        if(strstr(ptr, ".if."))
+        if (strstr(ptr, ".if."))
         {
             char *if_ptr = NULL;
             if_ptr = strtok(ptr, "=");
             if_ptr = strtok(NULL, "=");
 
-            if(!strcmp(if_ptr, iface))
+            if (!strcmp(if_ptr, iface))
             {
+                OICFree(str);
                 return true;
             }
         }
 
     } while ((ptr = strtok(NULL, ";")));
 
+    OICFree(str);
     return false;
 }
 
 ESResult SetCallbackForUserData(ESReadUserdataCb readCb, ESWriteUserdataCb writeCb)
 {
-    if(!readCb && !writeCb)
+    if (!readCb && !writeCb)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "Both of callbacks for user data are null");
         return ES_ERROR;
@@ -170,27 +173,27 @@ OCStackResult initEasySetupResource(bool isSecured)
         OC_RSRVD_ES_URI_EASYSETUP, OCEntityHandlerCb,
         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
     }
-    if(res != OC_STACK_OK)
+    if (res != OC_STACK_OK)
     {
         OIC_LOG_V(ERROR, ES_RH_TAG, "Created EasySetup resource with result: %s", getResult(res));
         return res;
     }
 
     res = OCBindResourceTypeToResource(g_ESEasySetupResource.handle, OC_RSRVD_ES_RES_TYPE_COL);
-    if(res != OC_STACK_OK)
+    if (res != OC_STACK_OK)
     {
         OIC_LOG_V(ERROR, ES_RH_TAG, "Binding Resource type with result: %s", getResult(res));
         return res;
     }
 
     res = OCBindResourceInterfaceToResource(g_ESEasySetupResource.handle, OC_RSRVD_INTERFACE_LL);
-    if(res != OC_STACK_OK)
+    if (res != OC_STACK_OK)
     {
         OIC_LOG_V(ERROR, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
         return res;
     }
     res = OCBindResourceInterfaceToResource(g_ESEasySetupResource.handle, OC_RSRVD_INTERFACE_BATCH);
-    if(res != OC_STACK_OK)
+    if (res != OC_STACK_OK)
     {
         OIC_LOG_V(ERROR, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
         return res;
@@ -301,13 +304,19 @@ void updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* in
     if (OCRepPayloadGetIntArray(input, OC_RSRVD_ES_CONNECT, &connect_req, dimensions))
     {
         ESConnectRequest* connectRequest = (ESConnectRequest*)OICMalloc(sizeof(ESConnectRequest));
+        if (!connectRequest)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return NULL;
+        }
+
         int cntRequest = 0;
         for (int i = 0 ; i < NUM_CONNECT_TYPE ; ++i)
         {
             g_ESEasySetupResource.connectRequest[i] = ES_CONNECT_NONE;
             connectRequest->connect[i] = ES_CONNECT_NONE;
 
-            if(i < dimensions[0] &&
+            if (i < dimensions[0] &&
                 (connect_req[i] == ES_CONNECT_WIFI || connect_req[i] == ES_CONNECT_COAPCLOUD))
             {
                 g_ESEasySetupResource.connectRequest[cntRequest] = connect_req[i];
@@ -320,12 +329,12 @@ void updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* in
         connectRequest->numRequest = cntRequest;
         g_ESEasySetupResource.numRequest = cntRequest;
 
-        if(g_ESEasySetupResource.connectRequest[0] != ES_CONNECT_NONE)
+        if (g_ESEasySetupResource.connectRequest[0] != ES_CONNECT_NONE)
         {
             OIC_LOG(DEBUG, ES_RH_TAG, "Send ConnectRequest Callback To ES");
 
-            // TODO : Need to check appropriateness of gWiFiData
-            if(gConnectRequestEvtCb != NULL)
+            //@todo Need to check appropriateness of gWiFiData
+            if (gConnectRequestEvtCb != NULL)
             {
                 gConnectRequestEvtCb(ES_OK, connectRequest);
             }
@@ -336,9 +345,9 @@ void updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* in
         }
     }
 
-    if(ehRequest->query)
+    if (ehRequest->query)
     {
-        if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
+        if (CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
         {
             // When Provisioning resource has a POST with BatchInterface
             updateCoapCloudConfResource(input);
@@ -352,7 +361,7 @@ void updateWiFiConfResource(OCRepPayload* input)
 {
     ESWiFiConfData* wiFiData = (ESWiFiConfData*)OICMalloc(sizeof(ESWiFiConfData));
 
-    if(wiFiData == NULL)
+    if (wiFiData == NULL)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
         return ;
@@ -396,17 +405,17 @@ void updateWiFiConfResource(OCRepPayload* input)
         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.encType %u", g_ESWiFiConfResource.encType);
     }
 
-    if(gReadUserdataCb)
+    if (gReadUserdataCb)
     {
         gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_WIFICONF, &wiFiData->userdata);
     }
 
-    if(ssid || cred || authType!= -1 || encType != -1)
+    if (ssid || cred || authType!= -1 || encType != -1)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "Send WiFiConfRsrc Callback To ES");
 
-        // TODO : Need to check appropriateness of gWiFiData
-        if(gWifiConfRsrcEvtCb != NULL)
+        //@todo Need to check appropriateness of gWiFiData
+        if (gWifiConfRsrcEvtCb != NULL)
         {
             gWifiConfRsrcEvtCb(ES_OK, wiFiData);
         }
@@ -416,7 +425,7 @@ void updateWiFiConfResource(OCRepPayload* input)
         }
     }
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESWiFiConfResource.handle, OC_HIGH_QOS))
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESWiFiConfResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "Enrollee doesn't have any observer.");
     }
@@ -428,7 +437,7 @@ void updateCoapCloudConfResource(OCRepPayload* input)
 {
     ESCoapCloudConfData* cloudData = (ESCoapCloudConfData*)OICMalloc(sizeof(ESCoapCloudConfData));
 
-    if(cloudData == NULL)
+    if (cloudData == NULL)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
         return;
@@ -481,17 +490,17 @@ void updateCoapCloudConfResource(OCRepPayload* input)
         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESCoapCloudConfResource.ciServer %s", g_ESCoapCloudConfResource.ciServer);
     }
 
-    if(gReadUserdataCb)
+    if (gReadUserdataCb)
     {
         gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF, &cloudData->userdata);
     }
 
-    if(authCode || accessToken || authProvider || ciServer)
+    if (authCode || accessToken || authProvider || ciServer)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "Send CoapCloudConfRsrc Callback To ES");
 
-        // TODO : Need to check appropriateness of gCloudData
-        if(gCoapCloudConfRsrcEvtCb != NULL)
+        //@todo Need to check appropriateness of gCloudData
+        if (gCoapCloudConfRsrcEvtCb != NULL)
         {
             gCoapCloudConfRsrcEvtCb(ES_OK, cloudData);
         }
@@ -501,7 +510,7 @@ void updateCoapCloudConfResource(OCRepPayload* input)
         }
     }
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESCoapCloudConfResource.handle, OC_HIGH_QOS))
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESCoapCloudConfResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "CoapCloudConf resource doesn't have any observer.");
     }
@@ -513,7 +522,7 @@ void updateDevConfResource(OCRepPayload* input)
 {
     ESDevConfData* devConfData = (ESDevConfData*)OICMalloc(sizeof(ESDevConfData));
 
-    if(devConfData == NULL)
+    if (devConfData == NULL)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
         return;
@@ -546,17 +555,17 @@ void updateDevConfResource(OCRepPayload* input)
         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESDevConfResource.language %s", g_ESDevConfResource.language);
     }
 
-    if(gReadUserdataCb)
+    if (gReadUserdataCb)
     {
         gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_DEVCONF, &devConfData->userdata);
     }
 
-    if(country || language)
+    if (country || language)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "Send DevConfRsrc Callback To ES");
 
-        // TODO : Need to check appropriateness of gDevConfData
-        if(gDevConfRsrcEvtCb != NULL)
+        //@todo : Need to check appropriateness of gDevConfData
+        if (gDevConfRsrcEvtCb != NULL)
         {
             gDevConfRsrcEvtCb(ES_OK, devConfData);
         }
@@ -566,7 +575,7 @@ void updateDevConfResource(OCRepPayload* input)
         }
     }
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESDevConfResource.handle, OC_HIGH_QOS))
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESDevConfResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "devConfResource doesn't have any observer.");
     }
@@ -583,7 +592,7 @@ OCRepPayload* constructResponseOfWiFiConf(char *interface)
         return NULL;
     }
 
-    if(g_ESWiFiConfResource.handle == NULL)
+    if (g_ESWiFiConfResource.handle == NULL)
     {
         OIC_LOG(ERROR, ES_RH_TAG, "WiFiConf resource is not created");
         return NULL;
@@ -594,7 +603,7 @@ OCRepPayload* constructResponseOfWiFiConf(char *interface)
 
     OCRepPayload* repPayload = NULL;
     OCRepPayload* tempPayload = NULL;
-    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
+    if (!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
     {
         repPayload = OCRepPayloadCreate();
         if (!repPayload)
@@ -608,6 +617,11 @@ OCRepPayload* constructResponseOfWiFiConf(char *interface)
 
         size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
         char **interfaces = (char **)OICMalloc(3 * sizeof(char*));
+        if (!interfaces)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return NULL;
+        }
 
         interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
 
@@ -615,6 +629,11 @@ OCRepPayload* constructResponseOfWiFiConf(char *interface)
 
         size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
         char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));
+        if (!resourceTypes)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return NULL;
+        }
 
         resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_WIFICONF);
 
@@ -628,7 +647,13 @@ OCRepPayload* constructResponseOfWiFiConf(char *interface)
 
     size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_ESWiFiConfResource.numMode, 0, 0};
     int64_t *modes_64 = (int64_t *)OICMalloc(g_ESWiFiConfResource.numMode * sizeof(int64_t));
-    for(int i = 0 ; i < g_ESWiFiConfResource.numMode ; ++i)
+    if (!modes_64)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+        return NULL;
+    }
+
+    for (int i = 0 ; i < g_ESWiFiConfResource.numMode ; ++i)
     {
         modes_64[i] = g_ESWiFiConfResource.supportedMode[i];
     }
@@ -640,12 +665,12 @@ OCRepPayload* constructResponseOfWiFiConf(char *interface)
     OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, (int) g_ESWiFiConfResource.authType);
     OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) g_ESWiFiConfResource.encType);
 
-    if(gWriteUserdataCb)
+    if (gWriteUserdataCb)
     {
         gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_WIFICONF);
     }
 
-    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
+    if (!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
     {
         payload = tempPayload;
         OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
@@ -663,7 +688,7 @@ OCRepPayload* constructResponseOfCoapCloudConf(char *interface)
         return NULL;
     }
 
-    if(g_ESCoapCloudConfResource.handle == NULL)
+    if (g_ESCoapCloudConfResource.handle == NULL)
     {
         OIC_LOG(ERROR, ES_RH_TAG, "CoapCloudConf resource is not created");
         return NULL;
@@ -674,7 +699,7 @@ OCRepPayload* constructResponseOfCoapCloudConf(char *interface)
 
     OCRepPayload* repPayload = NULL;
     OCRepPayload* tempPayload = NULL;
-    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
+    if (!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
     {
         repPayload = OCRepPayloadCreate();
         if (!repPayload)
@@ -688,6 +713,11 @@ OCRepPayload* constructResponseOfCoapCloudConf(char *interface)
 
         size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
         char **interfaces = (char **)OICMalloc(3 * sizeof(char*));
+        if (!interfaces)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return NULL;
+        }
 
         interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
 
@@ -695,6 +725,11 @@ OCRepPayload* constructResponseOfCoapCloudConf(char *interface)
 
         size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
         char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));
+        if (!resourceTypes)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return NULL;
+        }
 
         resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF);
 
@@ -712,12 +747,12 @@ OCRepPayload* constructResponseOfCoapCloudConf(char *interface)
     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHPROVIDER, g_ESCoapCloudConfResource.authProvider);
     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CISERVER, g_ESCoapCloudConfResource.ciServer);
 
-    if(gWriteUserdataCb)
+    if (gWriteUserdataCb)
     {
         gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF);
     }
 
-    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
+    if (!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
     {
         payload = tempPayload;
         OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
@@ -735,7 +770,7 @@ OCRepPayload* constructResponseOfDevConf(char *interface)
         return NULL;
     }
 
-    if(g_ESDevConfResource.handle == NULL)
+    if (g_ESDevConfResource.handle == NULL)
     {
         OIC_LOG(ERROR, ES_RH_TAG, "DevConf resource is not created");
         return NULL;
@@ -746,7 +781,7 @@ OCRepPayload* constructResponseOfDevConf(char *interface)
 
     OCRepPayload* repPayload = NULL;
     OCRepPayload* tempPayload = NULL;
-    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
+    if (!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
     {
         repPayload = OCRepPayloadCreate();
         if (!repPayload)
@@ -760,6 +795,11 @@ OCRepPayload* constructResponseOfDevConf(char *interface)
 
         size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
         char **interfaces = (char **)OICMalloc(3 * sizeof(char*));
+        if (!interfaces)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return NULL;
+        }
 
         interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
 
@@ -767,6 +807,11 @@ OCRepPayload* constructResponseOfDevConf(char *interface)
 
         size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
         char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));
+        if (!resourceTypes)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return NULL;
+        }
 
         resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_DEVCONF);
 
@@ -784,12 +829,12 @@ OCRepPayload* constructResponseOfDevConf(char *interface)
     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LANGUAGE, g_ESDevConfResource.language);
     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_COUNTRY, g_ESDevConfResource.country);
 
-    if(gWriteUserdataCb)
+    if (gWriteUserdataCb)
     {
         gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
     }
 
-    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
+    if (!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
     {
         payload = tempPayload;
         OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
@@ -808,8 +853,7 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
     }
 
     // Requested interface is Link list interface
-    //if(ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL))
-    if(!ehRequest->query ||
+    if (!ehRequest->query ||
         (ehRequest->query && !strcmp(ehRequest->query, "")) ||
         (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL)) ||
         (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
@@ -818,10 +862,10 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
 
         int childResCnt = 0;
 
-        if(g_ESWiFiConfResource.handle != NULL)
+        if (g_ESWiFiConfResource.handle != NULL)
         {
             OCRepPayload *add = OCRepPayloadCreate();
-            if(!add)
+            if (!add)
             {
                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
                 return NULL;
@@ -833,7 +877,7 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
             char **resourceInterface = NULL;
             resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
 
-            if(!resourceType || !resourceInterface)
+            if (!resourceType || !resourceInterface)
             {
                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
                 return NULL;
@@ -872,10 +916,10 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
             arrayPayload[childResCnt++] = add;
         }
 
-        if(g_ESDevConfResource.handle != NULL)
+        if (g_ESDevConfResource.handle != NULL)
         {
             OCRepPayload *add = OCRepPayloadCreate();
-            if(!add)
+            if (!add)
             {
                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
                 return NULL;
@@ -887,7 +931,7 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
             char **resourceInterface = NULL;
             resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
 
-            if(!resourceType || !resourceInterface)
+            if (!resourceType || !resourceInterface)
             {
                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
                 return NULL;
@@ -926,10 +970,10 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
             arrayPayload[childResCnt++] = add;
         }
 
-        if(g_ESCoapCloudConfResource.handle != NULL)
+        if (g_ESCoapCloudConfResource.handle != NULL)
         {
             OCRepPayload *add = OCRepPayloadCreate();
-            if(!add)
+            if (!add)
             {
                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
                 return NULL;
@@ -941,7 +985,7 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
             char **resourceInterface = NULL;
             resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
 
-            if(!resourceType || !resourceInterface)
+            if (!resourceType || !resourceInterface)
             {
                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
                 return NULL;
@@ -982,7 +1026,7 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
 
         size_t dimensions[MAX_REP_ARRAY_DEPTH] = {childResCnt, 0, 0};
 
-        if(!ehRequest->query ||
+        if (!ehRequest->query ||
             (ehRequest->query && !strcmp(ehRequest->query, "")) ||
             (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
         {
@@ -997,11 +1041,11 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
             OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, g_ESEasySetupResource.status);
             OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, g_ESEasySetupResource.lastErrCode);
 
-            if(g_ESEasySetupResource.numRequest > 0)
+            if (g_ESEasySetupResource.numRequest > 0)
             {
                 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_ESEasySetupResource.numRequest, 0, 0};
                 int64_t *connectRequest = (int64_t *)OICMalloc(g_ESEasySetupResource.numRequest  * sizeof(int64_t));
-                if(!connectRequest)
+                if (!connectRequest)
                 {
                     OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
                     return NULL;
@@ -1020,7 +1064,7 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
                 OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_CONNECT, NULL, dimensions);
             }
 
-            if(gWriteUserdataCb)
+            if (gWriteUserdataCb)
             {
                 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_EASYSETUP);
             }
@@ -1049,7 +1093,7 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
 
         size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {3, 0, 0};
         char **interfaces = (char **)OICMalloc(3 * sizeof(char*));
-        if(!interfaces)
+        if (!interfaces)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
             return NULL;
@@ -1063,7 +1107,7 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
 
         size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {2, 0, 0};
         char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));
-        if(!resourceTypes)
+        if (!resourceTypes)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
             return NULL;
@@ -1076,17 +1120,17 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
 
         OCRepPayloadSetPropInt(repPayload, OC_RSRVD_ES_PROVSTATUS, g_ESEasySetupResource.status);
         OCRepPayloadSetPropInt(repPayload, OC_RSRVD_ES_LAST_ERRORCODE, g_ESEasySetupResource.lastErrCode);
-        if(g_ESEasySetupResource.numRequest > 0)
+        if (g_ESEasySetupResource.numRequest > 0)
         {
             size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_ESEasySetupResource.numRequest, 0, 0};
             int64_t *connectRequest = (int64_t *)OICMalloc(g_ESEasySetupResource.numRequest  * sizeof(int64_t));
-            if(!connectRequest)
+            if (!connectRequest)
             {
                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
                 return NULL;
             }
 
-            for(int i = 0 ; i < g_ESEasySetupResource.numRequest  ; ++i)
+            for (int i = 0 ; i < g_ESEasySetupResource.numRequest  ; ++i)
             {
                 connectRequest[i] = g_ESEasySetupResource.connectRequest[i];
             }
@@ -1099,7 +1143,7 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
             OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_CONNECT, NULL, dimensions);
         }
 
-        if(gWriteUserdataCb)
+        if (gWriteUserdataCb)
         {
             gWriteUserdataCb(repPayload, OC_RSRVD_ES_RES_TYPE_EASYSETUP);
         }
@@ -1107,29 +1151,29 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
         OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
     }
 
-    if(ehRequest->query)
+    if (ehRequest->query)
     {
-        if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
+        if (CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
         {// When Provisioning resource has a GET with BatchInterface
             OCRepPayload* head = payload;
             OCRepPayload* nextPayload = NULL;
 
             nextPayload = constructResponseOfWiFiConf(OC_RSRVD_INTERFACE_BATCH);
-            if(nextPayload != NULL)
+            if (nextPayload != NULL)
             {
                 payload->next = nextPayload;
                 payload = payload->next;
             }
 
             nextPayload = constructResponseOfCoapCloudConf(OC_RSRVD_INTERFACE_BATCH);
-            if(nextPayload != NULL)
+            if (nextPayload != NULL)
             {
                 payload->next = nextPayload;
                 payload = payload->next;
             }
 
             nextPayload = constructResponseOfDevConf(OC_RSRVD_INTERFACE_BATCH);
-            if(nextPayload != NULL)
+            if (nextPayload != NULL)
             {
                 payload->next = nextPayload;
             }
@@ -1148,7 +1192,7 @@ OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMa
     bool maskFlag = false;
 
     res = initEasySetupResource(isSecured);
-    if(res != OC_STACK_OK)
+    if (res != OC_STACK_OK)
     {
         // TODO: destroy logic will be added
         OIC_LOG_V(ERROR, ES_RH_TAG, "initEasySetupResource result: %s", getResult(res));
@@ -1156,18 +1200,18 @@ OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMa
         return res;
     }
 
-    if((resourceMask & ES_WIFICONF_RESOURCE) == ES_WIFICONF_RESOURCE)
+    if ((resourceMask & ES_WIFICONF_RESOURCE) == ES_WIFICONF_RESOURCE)
     {
         maskFlag = true;
         res = initWiFiConfResource(isSecured);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "initWiFiConfResource result: %s", getResult(res));
             return res;
         }
 
         res = OCBindResource(g_ESEasySetupResource.handle, g_ESWiFiConfResource.handle);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "Bind WiFiConfResource result: %s", getResult(res));
             return res;
@@ -1175,43 +1219,43 @@ OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMa
 
     }
 
-    if((resourceMask & ES_COAPCLOUDCONF_RESOURCE) == ES_COAPCLOUDCONF_RESOURCE)
+    if ((resourceMask & ES_COAPCLOUDCONF_RESOURCE) == ES_COAPCLOUDCONF_RESOURCE)
     {
         maskFlag = true;
         res = initCoapCloudConfResource(isSecured);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "initCoapCloudConfResource result: %s", getResult(res));
             return res;
         }
 
         res = OCBindResource(g_ESEasySetupResource.handle, g_ESCoapCloudConfResource.handle);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "Bind CoapCloudConfResource result: %s", getResult(res));
             return res;
         }
     }
 
-    if((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
+    if ((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
     {
         maskFlag = true;
         res = initDevConfResource(isSecured);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "initDevConf result: %s", getResult(res));
             return res;
         }
 
         res = OCBindResource(g_ESEasySetupResource.handle, g_ESDevConfResource.handle);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "Bind DevConfResource result: %s", getResult(res));
             return res;
         }
     }
 
-    if(maskFlag == false)
+    if (maskFlag == false)
     {
         OIC_LOG_V(ERROR, ES_RH_TAG, "Invalid ResourceMask");
         return OC_STACK_ERROR;
@@ -1229,7 +1273,7 @@ OCStackResult DeleteEasySetupResources()
     if (g_ESWiFiConfResource.handle != NULL)
     {
         res = OCUnBindResource(g_ESEasySetupResource.handle, g_ESWiFiConfResource.handle);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind WiFi resource error with result: %s", getResult(res));
         }
@@ -1237,7 +1281,7 @@ OCStackResult DeleteEasySetupResources()
     if (g_ESCoapCloudConfResource.handle != NULL)
     {
         res = OCUnBindResource(g_ESEasySetupResource.handle, g_ESCoapCloudConfResource.handle);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind CloudServer resource error with result: %s", getResult(res));
         }
@@ -1245,7 +1289,7 @@ OCStackResult DeleteEasySetupResources()
     if (g_ESDevConfResource.handle != NULL)
     {
         res = OCUnBindResource(g_ESEasySetupResource.handle, g_ESDevConfResource.handle);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind DevConf resource error with result: %s", getResult(res));
         }
@@ -1260,7 +1304,7 @@ OCStackResult DeleteEasySetupResources()
         }
     }
 
-    if(g_ESCoapCloudConfResource.handle != NULL)
+    if (g_ESCoapCloudConfResource.handle != NULL)
     {
         res = OCDeleteResource(g_ESCoapCloudConfResource.handle);
         if (res != OC_STACK_OK)
@@ -1269,7 +1313,7 @@ OCStackResult DeleteEasySetupResources()
         }
     }
 
-    if(g_ESDevConfResource.handle != NULL)
+    if (g_ESDevConfResource.handle != NULL)
     {
         res = OCDeleteResource(g_ESDevConfResource.handle);
         if (res != OC_STACK_OK)
@@ -1278,7 +1322,7 @@ OCStackResult DeleteEasySetupResources()
         }
     }
 
-    if(g_ESEasySetupResource.handle != NULL)
+    if (g_ESEasySetupResource.handle != NULL)
     {
         res = OCDeleteResource(g_ESEasySetupResource.handle);
         if (res != OC_STACK_OK)
@@ -1307,9 +1351,9 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRep
     OCRepPayload *getResp = NULL;
     *payload = NULL;
 
-    if(ehRequest->resource == g_ESEasySetupResource.handle)
+    if (ehRequest->resource == g_ESEasySetupResource.handle)
     {
-        if(ehRequest->query &&
+        if (ehRequest->query &&
             strcmp(ehRequest->query, "") &&
             !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL) &&
             !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH) &&
@@ -1323,9 +1367,9 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRep
             getResp = constructResponseOfEasySetup(ehRequest);
         }
     }
-    else if(ehRequest->resource == g_ESWiFiConfResource.handle)
+    else if (ehRequest->resource == g_ESWiFiConfResource.handle)
     {
-        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
+        if (CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
@@ -1335,9 +1379,9 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRep
             getResp = constructResponseOfWiFiConf(OC_RSRVD_INTERFACE_DEFAULT);
         }
     }
-    else if(ehRequest->resource == g_ESCoapCloudConfResource.handle)
+    else if (ehRequest->resource == g_ESCoapCloudConfResource.handle)
     {
-        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
+        if (CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
@@ -1347,9 +1391,9 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRep
             getResp = constructResponseOfCoapCloudConf(OC_RSRVD_INTERFACE_DEFAULT);
         }
     }
-    else if(ehRequest->resource == g_ESDevConfResource.handle)
+    else if (ehRequest->resource == g_ESDevConfResource.handle)
     {
-        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
+        if (CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
@@ -1389,9 +1433,9 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
         return ehResult;
     }
 
-    if(ehRequest->resource == g_ESEasySetupResource.handle)
+    if (ehRequest->resource == g_ESEasySetupResource.handle)
     {
-        if(ehRequest->query &&
+        if (ehRequest->query &&
             strcmp(ehRequest->query, "") &&
             !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH) &&
             !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
@@ -1404,9 +1448,9 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
             updateEasySetupResource(ehRequest, input);
         }
     }
-    else if(ehRequest->resource == g_ESWiFiConfResource.handle)
+    else if (ehRequest->resource == g_ESWiFiConfResource.handle)
     {
-        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
+        if (CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
@@ -1416,9 +1460,9 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
             updateWiFiConfResource(input);
         }
     }
-    else if(ehRequest->resource == g_ESCoapCloudConfResource.handle)
+    else if (ehRequest->resource == g_ESCoapCloudConfResource.handle)
     {
-        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
+        if (CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
@@ -1428,9 +1472,9 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
             updateCoapCloudConfResource(input);
         }
     }
-    else if(ehRequest->resource == g_ESDevConfResource.handle)
+    else if (ehRequest->resource == g_ESDevConfResource.handle)
     {
-        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
+        if (CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
@@ -1442,19 +1486,19 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
     }
 
     OCRepPayload *getResp = NULL;
-    if(ehRequest->resource == g_ESEasySetupResource.handle)
+    if (ehRequest->resource == g_ESEasySetupResource.handle)
     {
         getResp = constructResponseOfEasySetup(ehRequest);
     }
-    else if(ehRequest->resource == g_ESWiFiConfResource.handle)
+    else if (ehRequest->resource == g_ESWiFiConfResource.handle)
     {
         getResp = constructResponseOfWiFiConf(OC_RSRVD_INTERFACE_DEFAULT);
     }
-    else if(ehRequest->resource == g_ESCoapCloudConfResource.handle)
+    else if (ehRequest->resource == g_ESCoapCloudConfResource.handle)
     {
         getResp = constructResponseOfCoapCloudConf(OC_RSRVD_INTERFACE_DEFAULT);
     }
-    else if(ehRequest->resource == g_ESDevConfResource.handle)
+    else if (ehRequest->resource == g_ESDevConfResource.handle)
     {
         getResp = constructResponseOfDevConf(OC_RSRVD_INTERFACE_DEFAULT);
     }
@@ -1575,7 +1619,7 @@ OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty)
     OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "WiFi Freq : %d", g_ESWiFiConfResource.supportedFreq);
 
     int modeIdx = 0;
-    while((deviceProperty->WiFi).mode[modeIdx] != WiFi_EOF)
+    while ((deviceProperty->WiFi).mode[modeIdx] != WiFi_EOF)
     {
         g_ESWiFiConfResource.supportedMode[modeIdx] = (deviceProperty->WiFi).mode[modeIdx];
         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "WiFi Mode : %d", g_ESWiFiConfResource.supportedMode[modeIdx]);
@@ -1590,12 +1634,12 @@ OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty)
                                                             (deviceProperty->DevConf).modelNumber);
     OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "Model Number : %s", g_ESDevConfResource.modelNumber);
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESWiFiConfResource.handle, OC_HIGH_QOS))
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESWiFiConfResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "wifiResource doesn't have any observers.");
     }
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESDevConfResource.handle, OC_HIGH_QOS))
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESDevConfResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "devConfResource doesn't have any observers.");
     }
@@ -1611,7 +1655,7 @@ OCStackResult SetEnrolleeState(ESEnrolleeState esState)
     g_ESEasySetupResource.status = esState;
     OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "Enrollee Status : %d", g_ESEasySetupResource.status);
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESEasySetupResource.handle, OC_HIGH_QOS))
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESEasySetupResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "provResource doesn't have any observers.");
     }
@@ -1627,7 +1671,7 @@ OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode)
     g_ESEasySetupResource.lastErrCode = esErrCode;
     OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "Enrollee ErrorCode : %d", g_ESEasySetupResource.lastErrCode);
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESEasySetupResource.handle, OC_HIGH_QOS))
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESEasySetupResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "provResource doesn't have any observers.");
     }
@@ -1638,7 +1682,7 @@ OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode)
 
 OCEntityHandlerResult CheckEhRequestPayload(OCEntityHandlerRequest *ehRequest)
 {
-    if!(ehRequest->query) ||
+    if (!(ehRequest->query) ||
                 (ehRequest->query &&
                 (strcmp(ehRequest->query, "") && !CompareResourceInterface(ehRequest->query,
                                                                         OC_RSRVD_INTERFACE_DEFAULT))))