resource-directory: Check links before free 27/22127/5
authorPhilippe Coval <philippe.coval@osg.samsung.com>
Thu, 24 Aug 2017 14:23:51 +0000 (16:23 +0200)
committerMats Wichmann <mats@linux.com>
Wed, 27 Sep 2017 20:04:58 +0000 (20:04 +0000)
In case if pointer has not been assigned

This is also suppressing a valgrind warning
when running test resource/csdk/stack/test/stacktests:

  2,208 bytes in 1 blocks \
  are possibly lost in loss record 0 if 0

Bug: https://jira.iotivity.org/browse/IOT-2645
Change-Id: Ifd44172a1f7755ec253748f6f02fbfd1dcacdd39
Origin: https://gerrit.iotivity.org/gerrit/#/c/22107/
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/22107
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: George Nash <george.nash@intel.com>
Reviewed-by: Mats Wichmann <mats@linux.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
(cherry picked from commit 2c926be5e04dd982316c05c461c9a95fd0beae9a)

resource/csdk/resource-directory/src/rd_client.c

index 0a60445..a7d9dcb 100644 (file)
@@ -109,11 +109,14 @@ OCStackApplicationResult RDPublishCallback(void *ctx,
     }
 
 exit:
-    for (size_t i = 0; i < dimensions[0]; i++)
+    if (links)
     {
-        OCRepPayloadDestroy(links[i]);
+        for (size_t i = 0; i < dimensions[0]; i++)
+        {
+            OCRepPayloadDestroy(links[i]);
+        }
+        OICFree(links);
     }
-    OICFree(links);
     return cbData->cb(cbData->context, handle, clientResponse);
 }