Free payload and option in clientCB.
authorZiran Sun <ziran.sun@samsung.com>
Fri, 19 May 2017 18:21:25 +0000 (19:21 +0100)
committerAshok Babu Channa <ashok.channa@samsung.com>
Sun, 21 May 2017 05:06:14 +0000 (05:06 +0000)
This is to fix crash issue when OCF client sends unicast GET to OIC server.

Bug: https://jira.iotivity.org/browse/IOT-2329
Change-Id: Id3992563e3d7a8db02f8308ab00eaea1f93db5e5
Signed-off-by: Ziran Sun <ziran.sun@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20157
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/stack/src/occlientcb.c
resource/csdk/stack/src/ocstack.c

index 39f5436e202cdd4283032686873cf8aa99f816c6..32b0e96dd6f1c08aab7de7d0d8b0ee9a426ccc98 100755 (executable)
@@ -88,6 +88,8 @@ AddClientCB(ClientCB** clientCB, OCCallbackData* cbData,
             if (!options || !numOptions)
             {
                 OIC_LOG (INFO, TAG, "No options present");
+                cbNode->options = NULL;
+                cbNode->numOptions = 0;
             }
             else
             {
@@ -106,6 +108,8 @@ AddClientCB(ClientCB** clientCB, OCCallbackData* cbData,
             if (!payload || !payloadSize)
             {
                 OIC_LOG (INFO, TAG, "No payload present");
+                cbNode->payload = NULL;
+                cbNode->payloadSize = 0;
             }
             else
             {
@@ -207,6 +211,14 @@ void DeleteClientCB(ClientCB * cbNode)
         OIC_TRACE_BUFFER("OIC_RI_CLIENTCB:DeleteClientCB:token:",
                          (const uint8_t *)cbNode->token, cbNode->tokenLength);
         CADestroyToken (cbNode->token);
+        if (cbNode->options)
+        {
+            OICFree(cbNode->options);
+        }
+        if(cbNode->payload)
+        {
+            OICFree(cbNode->payload);
+        }
         OICFree(cbNode->devAddr);
         OICFree(cbNode->handle);
         if (cbNode->requestUri)
index 9107781315bde42dfa6fd0345b9962b305f81e08..5b183511d79e7513d44ce5d0b872438c864935bf 100644 (file)
@@ -1604,6 +1604,8 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
                 if (!cbNode->options || !cbNode->numOptions)
                 {
                     OIC_LOG (INFO, TAG, "No options present in cbNode");
+                    requestData.options = NULL;
+                    requestData.numOptions = 0;
                 }
                 else
                 {
@@ -1623,6 +1625,8 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
                 if (!cbNode->payload || !cbNode->payloadSize)
                 {
                     OIC_LOG (INFO, TAG, "No payload present in cbNode");
+                    requestData.payload = NULL;
+                    requestData.payloadSize = 0;
                 }
                 else
                 {