resource-encapsulation: use OICFree for query
authorPhilippe Coval <philippe.coval@osg.samsung.com>
Fri, 25 Aug 2017 08:24:35 +0000 (10:24 +0200)
committerPhil Coval <philippe.coval@osg.samsung.com>
Fri, 13 Oct 2017 07:52:58 +0000 (07:52 +0000)
Track memory allocations using oic_malloc, oic_string.

This will suppress valgrind warning about using delete on C string,
previously, ocEntityHandlerRequest.query was allocated using C strdup,
so free should be used not C++ delete[].

Conflicts:
service/resource-encapsulation/src/serverBuilder/unittests/RCSResourceObjectTest.cpp

Bug: https://jira.iotivity.org/browse/IOT-2267
Origin: https://gerrit.iotivity.org/gerrit/#/c/22129
Change-Id: I86a3a3dfee8492656ee89de5913617369bf1fbb3
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/22129
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Mats Wichmann <mats@linux.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
service/resource-encapsulation/src/serverBuilder/unittests/RCSResourceObjectTest.cpp

index 5d85f84f4ba4afa2b8919862b1c6e2ed22c9273c..ad33726b2598c3cc05a1647490c85e38ce62b8dd 100644 (file)
@@ -18,6 +18,8 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+#include "oic_malloc.h"
+#include "oic_string.h"
 #include "UnitTestHelperWithFakeOCPlatform.h"
 
 #include "RCSResourceObject.h"
@@ -430,16 +432,13 @@ public:
         if(!interface.empty())
         {
             const string query = string("if=" + interface);
-            auto cQuery = new char [query.size()+1];
-            std::strcpy(cQuery, query.c_str());
-            ocEntityHandlerRequest.query = const_cast<char *> (cQuery);
+            ocEntityHandlerRequest.query = OICStrdup(query.c_str());
         }
 
         formResourceRequest(OC_REQUEST_FLAG, &ocEntityHandlerRequest, request);
 
         OCRepPayloadDestroy((OCRepPayload *)ocEntityHandlerRequest.payload);
-
-        delete[] ocEntityHandlerRequest.query;
+        OICFreeAndSetToNull((void**) &ocEntityHandlerRequest.query);
 
         return request;
     }