Fix a wrong usage of return value of getMediatorDevId API
authorJihun Ha <jihun.ha@samsung.com>
Tue, 7 Feb 2017 01:03:53 +0000 (10:03 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 7 Feb 2017 06:54:03 +0000 (06:54 +0000)
Instead of OCUUIdentity *, a value of std::string should be returned.
Additionally, removed a defect point in returning a value after OICFree

Change-Id: Ibcd204b14ea6f488f689ff0ff61da9b618124a4d
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17085
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.h

index 80ab773..fcde0b0 100755 (executable)
@@ -624,37 +624,34 @@ namespace OIC
             return ESResult::ES_OK;
         }
 
-        OCUUIdentity* EnrolleeSecurity::getMediatorDevID()
+        std::string EnrolleeSecurity::getMediatorDevID()
         {
             OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "getMediatorDevID IN");
             OCUUIdentity* mediatorDevId = (OCUUIdentity* )OICMalloc(sizeof(OCUUIdentity));
             if(!mediatorDevId)
             {
                 OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "provisionOwnership: OICMalloc error return");
-                return NULL;
+                return {};
             }
 
             if(OC::OCPlatform::getDeviceId(mediatorDevId) != OC_STACK_OK)
             {
                 OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "getDeviceId is failed.");
                 OICFree(mediatorDevId);
-                return NULL;
+                return {};
             }
 
             char uuidString[UUID_STRING_SIZE];
             if(OCConvertUuidToString(mediatorDevId->id, uuidString))
             {
-                m_mediatorID = uuidString;
                 OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Mediator UUID : %s", uuidString);
                 OICFree(mediatorDevId);
+                return std::string(uuidString);
             }
-            else
-            {
-                OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "OCConvertUuidToString is failed.");
-                OICFree(mediatorDevId);
-                return NULL;
-            }
-            return mediatorDevId;
+
+            OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "OCConvertUuidToString is failed.");
+            OICFree(mediatorDevId);
+            return {};
         }
 
         ESResult EnrolleeSecurity::provisionOwnership(SecurityProvStatusCbWithOption callback)
@@ -665,12 +662,16 @@ namespace OIC
 
             ESOwnershipTransferData ownershipTransferData;
 
-            OCUUIdentity* mediatorDevId = getMediatorDevID();
-            if(!mediatorDevId)
+            std::string mediatorDevIdStr = getMediatorDevID();
+            if(mediatorDevIdStr.empty())
             {
                 OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "getMediatorDevID is failed.");
                 return res;
             }
+            else
+            {
+                m_mediatorID = mediatorDevIdStr;
+            }
 
             res = discoverTargetSecureResource();
 
index 5ceaa9b..6c023b1 100755 (executable)
@@ -100,7 +100,7 @@ namespace OIC
                                                 std::string& uuidString);
             std::string getResourceDeviceAddress(const std::string& host);
             bool isOwnerIDMatched(std::shared_ptr< OC::OCSecureResource > foundDevice);
-            OCUUIdentity* getMediatorDevID();
+            std::string getMediatorDevID();
 
 #if defined(__WITH_DTLS__) && defined(__WITH_TLS__)
         public: