Imported Upstream version 1.2.0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / common / src / caremotehandler.c
index 61a2509..6a7fea2 100644 (file)
@@ -247,16 +247,14 @@ CAResult_t CACloneInfo(const CAInfo_t *info, CAInfo_t *clone)
     //Do not free clone. we cannot declare it const, as the content is modified
     if ((info->token) && (0 < info->tokenLength))
     {
-        char *temp = NULL;
-
         // allocate token field
         uint8_t len = info->tokenLength;
 
-        temp = (char *) OICMalloc(len * sizeof(char));
+        char *temp = (char *) OICMalloc(len * sizeof(char));
         if (!temp)
         {
             OIC_LOG(ERROR, TAG, "CACloneInfo Out of memory");
-            return CA_MEMORY_ALLOC_FAILED;
+            goto exit;
         }
 
         memcpy(temp, info->token, len);
@@ -274,8 +272,7 @@ CAResult_t CACloneInfo(const CAInfo_t *info, CAInfo_t *clone)
         if (!clone->options)
         {
             OIC_LOG(ERROR, TAG, "CACloneInfo Out of memory");
-            CADestroyInfoInternal(clone);
-            return CA_MEMORY_ALLOC_FAILED;
+            goto exit;
         }
         memcpy(clone->options, info->options, sizeof(CAHeaderOption_t) * info->numOptions);
         clone->numOptions = info->numOptions;
@@ -290,8 +287,7 @@ CAResult_t CACloneInfo(const CAInfo_t *info, CAInfo_t *clone)
         if (!temp)
         {
             OIC_LOG(ERROR, TAG, "CACloneInfo Out of memory");
-            CADestroyInfoInternal(clone);
-            return CA_MEMORY_ALLOC_FAILED;
+            goto exit;
         }
         memcpy(temp, info->payload, info->payloadSize);
 
@@ -309,8 +305,7 @@ CAResult_t CACloneInfo(const CAInfo_t *info, CAInfo_t *clone)
         if (!temp)
         {
             OIC_LOG(ERROR, TAG, "CACloneInfo Out of memory");
-            CADestroyInfoInternal(clone);
-            return CA_MEMORY_ALLOC_FAILED;
+            goto exit;
         }
 
         // save the resourceUri
@@ -326,4 +321,7 @@ CAResult_t CACloneInfo(const CAInfo_t *info, CAInfo_t *clone)
 
     return CA_STATUS_OK;
 
+exit:
+    CADestroyInfoInternal(clone);
+    return CA_MEMORY_ALLOC_FAILED;
 }