Uninitialized payload pointer mey be freed 25/24825/5
authorMats Wichmann <mats@linux.com>
Sat, 21 Apr 2018 12:55:39 +0000 (06:55 -0600)
committerMats Wichmann <mats@linux.com>
Tue, 24 Apr 2018 23:41:23 +0000 (23:41 +0000)
initialize response on declaration; don't free if pointer is null.

Change-Id: I9936a4f24c4ab6f8c322a2493ab5a1c303cd97cb
Signed-off-by: Mats Wichmann <mats@linux.com>
resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp

index d4b688e..1d5d470 100644 (file)
@@ -506,6 +506,7 @@ OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
     memset(response.sendVendorSpecificHeaderOptions, 0,
             sizeof response.sendVendorSpecificHeaderOptions);
     memset(response.resourceUri, 0, sizeof response.resourceUri);
+    response.payload = nullptr;
     OCRepPayload* payload = nullptr;
 
 
@@ -570,7 +571,11 @@ OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
         }
     }
 
-    OCPayloadDestroy(response.payload);
+
+    if (response.payload != nullptr)
+    {
+        OCPayloadDestroy(response.payload);
+    }
     return ehResult;
 }