Modify CopyRequest() and add free code for ehRequest after confirm 20/201720/1
authorOleksii Beketov <ol.beketov@samsung.com>
Mon, 11 Mar 2019 16:45:51 +0000 (18:45 +0200)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 19 Mar 2019 05:03:25 +0000 (14:03 +0900)
Sync with SES PR #546

https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/commit/656106cc245720c4c1645948b033bed45aee773c
(cherry picked from 656106cc245720c4c1645948b033bed45aee773c)

Change-Id: I3a891f44c9d6c270f752eed6947d02a390b2d777
Signed-off-by: Oleksii Beketov <ol.beketov@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
resource/csdk/security/src/doxmresource.c

index 811fa89..116bb9a 100644 (file)
@@ -1104,6 +1104,23 @@ void UnsetInformOxmSelCB()
 #if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
 static OCEntityHandlerResult HandleDoxmPostRequest(OCEntityHandlerRequest * ehRequest);
 
+static void DestroyEntityHandlerRequest(OCEntityHandlerRequest * ehRequest)
+{
+    if (ehRequest == NULL) {
+        OIC_LOG(WARNING, TAG, "ehRequest is NULL");
+        return;
+    }
+
+    OICFree(ehRequest->query);
+
+    if (ehRequest->payload) {
+        OICFree(((OCSecurityPayload *)ehRequest->payload)->securityData);
+        OICFree(ehRequest->payload);
+    }
+
+    OICFree(ehRequest);
+}
+
 void * WaitConfirm(OCEntityHandlerRequest * ehRequest)
 {
     bool confirmResult = false, confirmState = false;
@@ -1126,6 +1143,10 @@ void * WaitConfirm(OCEntityHandlerRequest * ehRequest)
         HandleDoxmPostRequest(ehRequest);
         return NULL;
     }
+
+    DestroyEntityHandlerRequest(ehRequest);
+
+    return NULL;
 }
 
 static OCEntityHandlerRequest *CopyRequest(OCEntityHandlerRequest *entityHandlerRequest)
@@ -1139,7 +1160,7 @@ static OCEntityHandlerRequest *CopyRequest(OCEntityHandlerRequest *entityHandler
     }
 
     OCEntityHandlerRequest *copyOfRequest =
-            (OCEntityHandlerRequest *)OICMalloc(sizeof(OCEntityHandlerRequest));
+            (OCEntityHandlerRequest *)OICCalloc(1, sizeof(OCEntityHandlerRequest));
     if(!copyOfRequest)
     {
         OIC_LOG(ERROR, TAG, "Copy failed due to allocation failure");
@@ -1162,7 +1183,7 @@ static OCEntityHandlerRequest *CopyRequest(OCEntityHandlerRequest *entityHandler
     if (entityHandlerRequest->payload)
     {
         copyOfRequest->payload =
-                (OCSecurityPayload *)OICMalloc(sizeof(OCSecurityPayload));
+                (OCSecurityPayload *)OICCalloc(1, sizeof(OCSecurityPayload));
         if(!copyOfRequest->payload)
         {
             OIC_LOG(ERROR, TAG, "Copy failed due to allocation failure");
@@ -1171,11 +1192,10 @@ static OCEntityHandlerRequest *CopyRequest(OCEntityHandlerRequest *entityHandler
             return NULL;
         }
 
-        if (((OCSecurityPayload *)copyOfRequest->payload)->securityData &&
-            ((OCSecurityPayload *)entityHandlerRequest->payload)->payloadSize)
+        if (((OCSecurityPayload *)entityHandlerRequest->payload)->payloadSize)
         {
             ((OCSecurityPayload *)copyOfRequest->payload)->securityData =
-                    (uint8_t *)OICMalloc(((OCSecurityPayload *)entityHandlerRequest->payload)->payloadSize);
+                    (uint8_t *)OICCalloc(1, ((OCSecurityPayload *)entityHandlerRequest->payload)->payloadSize);
             if(!((OCSecurityPayload *)copyOfRequest->payload)->securityData)
             {
                 OIC_LOG(ERROR, TAG, "Copy failed due to allocation failure");
@@ -1191,10 +1211,6 @@ static OCEntityHandlerRequest *CopyRequest(OCEntityHandlerRequest *entityHandler
 
             ((OCSecurityPayload *)(copyOfRequest->payload))->payloadSize =
                     ((OCSecurityPayload *)(entityHandlerRequest->payload))->payloadSize;
-
-            memcpy(((OCSecurityPayload *)copyOfRequest->payload)->securityData,
-                   ((OCSecurityPayload *)entityHandlerRequest->payload)->securityData,
-                   ((OCSecurityPayload *)entityHandlerRequest->payload)->payloadSize);
         }
 
         copyOfRequest->payload->type = entityHandlerRequest->payload->type;