From 5346f48842f733190511003125a7b2ea6b69eb71 Mon Sep 17 00:00:00 2001 From: Doug Hudson Date: Thu, 21 Aug 2014 20:44:13 -0400 Subject: [PATCH] 1. Fixed double free in OCDoResource that caused segfault 2. Modified csdk/stack/test/stacktests.cpp because API change caused ocstack unit test build to fail. Change-Id: Ie06a5ad603e40ea67fbaadead66b4334d290c8ac --- csdk/stack/src/ocstack.c | 5 +++-- csdk/stack/test/README | 13 ++++++++----- csdk/stack/test/stacktests.cpp | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/csdk/stack/src/ocstack.c b/csdk/stack/src/ocstack.c index 3c1ef97..4b23d91 100644 --- a/csdk/stack/src/ocstack.c +++ b/csdk/stack/src/ocstack.c @@ -319,6 +319,7 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ if(!*handle) { result = OC_STACK_NO_MEMORY; + OCFree(*handle); goto exit; } @@ -326,6 +327,8 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ if (!token) { result = OC_STACK_NO_MEMORY; + OCFree(*handle); + OCFree(token); goto exit; } if((result = AddClientCB(&clientCB, cbData, token, *handle, method)) != OC_STACK_OK) @@ -342,8 +345,6 @@ exit: { OC_LOG(ERROR, TAG, PCF("OCDoResource error")); FindAndDeleteClientCB(clientCB); - OCFree(token); - OCFree(*handle); } return result; } diff --git a/csdk/stack/test/README b/csdk/stack/test/README index f2426c1..c16e3b7 100644 --- a/csdk/stack/test/README +++ b/csdk/stack/test/README @@ -25,12 +25,15 @@ Unit Test Requirements: At the time of this writing this was done by running root/csdk/make deepclean - root/csdk/make + root/csdk/make BUILD=release *default + root/csdk/make BUILD=debug -5. Next, run +5. Next, build the ocstack root/csdk/stack/test/make clean - root/csdk/stack/test/make + root/csdk/stack/test/make BUILD=release *default + root/csdk/stack/test/make BUILD=debug -6. Run the test by - root/csdk/stack/test/stacktests +6. Run the unit test by + root/csdk/stack/test/release/stacktests + root/csdk/stack/test/debug/stacktests diff --git a/csdk/stack/test/stacktests.cpp b/csdk/stack/test/stacktests.cpp index c555ec3..c203d80 100644 --- a/csdk/stack/test/stacktests.cpp +++ b/csdk/stack/test/stacktests.cpp @@ -978,10 +978,10 @@ TEST(StackTest, BindEntityHandlerBad) { } -OCStackResult entityHandler(OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest) { +OCEntityHandlerResult entityHandler(OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest) { OC_LOG(INFO, TAG, "Entering entityHandler"); - return OC_STACK_OK; + return OC_EH_OK; } TEST(StackTest, BindEntityHandlerGood) { -- 2.7.4