Fix defects detected by static analysis
authorParkhi <h_w.park@samsung.com>
Thu, 15 Dec 2016 02:10:11 +0000 (11:10 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 19 Dec 2016 10:13:59 +0000 (10:13 +0000)
Change-Id: Ie07051e70f2b78fc9cdca6e1c1c0d59d7e5bc231
Signed-off-by: Parkhi <h_w.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15465
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
(cherry picked from commit ebce9d66d37228f8a91975d635f9b4c13036ef67)
Reviewed-on: https://gerrit.iotivity.org/gerrit/15665
Reviewed-by: Jihun Ha <jihun.ha@samsung.com>
service/easy-setup/mediator/richsdk/inc/ESRichCommon.h
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp
service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator.cpp
service/easy-setup/sampleapp/mediator/linux/richsdk_sample/submediator.cpp

index 17eedbe..7c1e8c3 100755 (executable)
@@ -77,7 +77,7 @@ namespace OIC
              *
              * @return a provisioning status property of Enrollee
              */
-            ProvStatus getProvStatus()
+            ProvStatus getProvStatus() const
             {
                 if(m_rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
                 {
@@ -92,7 +92,7 @@ namespace OIC
              *
              * @return a last error code property of Enrollee.
              */
-            ESErrorCode getLastErrCode()
+            ESErrorCode getLastErrCode() const
             {
                 if(m_rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
                 {
index e20c521..0ed2756 100755 (executable)
@@ -31,6 +31,7 @@
 #include "oic_string.h"
 #include "utlist.h"
 #include "srmutility.h"
+#include "aclresource.h"
 #include "internal/doxmresource.h"
 
 namespace OIC
@@ -807,7 +808,7 @@ namespace OIC
             {
                 res = ESResult::ES_OK;
             }
-
+            OCDeleteACLList(acl);
             return res;
         }
 
@@ -836,6 +837,7 @@ namespace OIC
             if(!rsrc)
             {
                 OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "createAcl: OICCalloc error return");
+                FreeRsrc(rsrc);
                 OCDeleteACLList(acl);
                 return NULL;
             }
@@ -846,6 +848,7 @@ namespace OIC
             if(!rsrc->href)
             {
                 OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG,  "createAcl: OICCalloc error return");
+                FreeRsrc(rsrc);
                 OCDeleteACLList(acl);
                 return NULL;
             }
@@ -854,10 +857,39 @@ namespace OIC
             size_t arrLen = 1;
             rsrc->typeLen = arrLen;
             rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
+            if(!rsrc->types)
+            {
+                OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG,  "createAcl: OICCalloc error return");
+                FreeRsrc(rsrc);
+                OCDeleteACLList(acl);
+                return NULL;
+            }
+            rsrc->types[0] = OICStrdup("rt");   // ignore
+            if(!rsrc->types[0])
+            {
+                OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG,  "createAcl: OICStrdup error return");
+                FreeRsrc(rsrc);
+                OCDeleteACLList(acl);
+                return NULL;
+            }
+
             rsrc->interfaceLen = 1;
             rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
-            rsrc->types[0] = OICStrdup("rt");   // ignore
+            if(!rsrc->interfaces)
+            {
+                OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG,  "createAcl: OICCalloc error return");
+                FreeRsrc(rsrc);
+                OCDeleteACLList(acl);
+                return NULL;
+            }
             rsrc->interfaces[0] = OICStrdup("if");  // ignore
+            if(!rsrc->interfaces[0])
+            {
+                OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG,  "createAcl: OICStrdup error return");
+                FreeRsrc(rsrc);
+                OCDeleteACLList(acl);
+                return NULL;
+            }
 
             LL_APPEND(ace->resources, rsrc);
 
index 41f0a78..32c85cd 100755 (executable)
@@ -52,12 +52,15 @@ int processUserInput(int min = std::numeric_limits<int>::min(),
 {
     assert(min <= max);
 
-    int input;
+    int input = 0;
 
     std::cin >> input;
     std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
 
-    if (!std::cin.fail() && min <= input && input <= max) return input;
+    if (!std::cin.fail() && min <= input && input <= max)
+    {
+        return input;
+    }
 
     std::cin.clear();
     std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
@@ -65,7 +68,7 @@ int processUserInput(int min = std::numeric_limits<int>::min(),
     throw std::runtime_error("Invalid Input, please try again");
 }
 
-void printConfiguration(EnrolleeConf conf)
+void printConfiguration(const EnrolleeConf& conf)
 {
     cout << "===========================================" << endl;
     cout << "\tDevice Name : " << conf.getDeviceName() << endl;
@@ -81,7 +84,7 @@ void printConfiguration(EnrolleeConf conf)
     cout << "===========================================" << endl;
 }
 
-void printStatus(EnrolleeStatus status)
+void printStatus(const EnrolleeStatus& status)
 {
     cout << "===========================================" << endl;
     cout << "\tProvStatus : " << status.getProvStatus() << endl;
@@ -439,7 +442,7 @@ int main()
             return -1;
         }
 #endif
-    }catch(OCException& e)
+    }catch (const std::exception& e)
     {
         std::cout << "Exception in main: "<<e.what();
     }
index 7e98942..7b70611 100755 (executable)
@@ -52,12 +52,15 @@ int processUserInput(int min = std::numeric_limits<int>::min(),
 {
     assert(min <= max);
 
-    int input;
+    int input = 0;
 
     std::cin >> input;
     std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
 
-    if (!std::cin.fail() && min <= input && input <= max) return input;
+    if (!std::cin.fail() && min <= input && input <= max)
+    {
+        return input;
+    }
 
     std::cin.clear();
     std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
@@ -65,7 +68,7 @@ int processUserInput(int min = std::numeric_limits<int>::min(),
     throw std::runtime_error("Invalid Input, please try again");
 }
 
-void printConfiguration(EnrolleeConf conf)
+void printConfiguration(const EnrolleeConf& conf)
 {
     cout << "===========================================" << endl;
     cout << "\tDevice Name : " << conf.getDeviceName() << endl;
@@ -81,7 +84,7 @@ void printConfiguration(EnrolleeConf conf)
     cout << "===========================================" << endl;
 }
 
-void printStatus(EnrolleeStatus status)
+void printStatus(const EnrolleeStatus& status)
 {
     cout << "===========================================" << endl;
     cout << "\tProvStatus : " << status.getProvStatus() << endl;
@@ -439,7 +442,7 @@ int main()
             return -1;
         }
 #endif
-    }catch(OCException& e)
+    }catch (const std::exception& e)
     {
         std::cout << "Exception in main: "<<e.what();
     }