From fdb1a7c2832ec327981a7fd0054b061ae9436db0 Mon Sep 17 00:00:00 2001 From: "jaesick.shin" Date: Thu, 1 Sep 2016 10:18:59 +0900 Subject: [PATCH] Resolve memory leak for unittest. change strdup to global variables. Change-Id: Ida35b98ad5fb5be8add9fa12b481cb8a2bee4dcb Signed-off-by: jaesick.shin Reviewed-on: https://gerrit.iotivity.org/gerrit/11235 Reviewed-by: Uze Choi Tested-by: Uze Choi --- service/notification/unittest/NSProviderTest.cpp | 31 +++++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/service/notification/unittest/NSProviderTest.cpp b/service/notification/unittest/NSProviderTest.cpp index 24e50f3..671515a 100755 --- a/service/notification/unittest/NSProviderTest.cpp +++ b/service/notification/unittest/NSProviderTest.cpp @@ -41,6 +41,9 @@ namespace NSConsumerSimulator g_consumerSimul; char * g_consumerID; + char g_title[100]; + char g_body[100]; + char g_sourceName[100]; } class TestWithMock: public testing::Test @@ -119,6 +122,10 @@ protected: } g_isStartedStack = true; + + strcpy(g_title, "Title"); + strcpy(g_body, "ContentText"); + strcpy(g_sourceName, "OIC"); } } @@ -228,9 +235,9 @@ TEST_F(NotificationProviderTest, NeverCallNotifyOnConsumerByAcceptIsFalse) NSMessage * msg = NSCreateMessage(); msgID = (int)msg->messageId; - msg->title = strdup(std::string("Title").c_str()); - msg->contentText = strdup(std::string("ContentText").c_str()); - msg->sourceName = strdup(std::string("OCF").c_str()); + msg->title = g_title; + msg->contentText = g_body; + msg->sourceName = g_sourceName; NSSendMessage(msg); { @@ -265,9 +272,9 @@ TEST_F(NotificationProviderTest, ExpectCallNotifyOnConsumerByAcceptIsTrue) NSMessage * msg = NSCreateMessage(); msgID = (int)msg->messageId; - msg->title = strdup(std::string("Title").c_str()); - msg->contentText = strdup(std::string("ContentText").c_str()); - msg->sourceName = strdup(std::string("OCF").c_str()); + msg->title = g_title; + msg->contentText = g_body; + msg->sourceName = g_sourceName; NSSendMessage(msg); std::unique_lock< std::mutex > lock{ mutexForCondition }; @@ -292,9 +299,9 @@ TEST_F(NotificationProviderTest, ExpectCallbackSyncOnReadToConsumer) NSMessage * msg = NSCreateMessage(); id = (int)msg->messageId; - msg->title = strdup(std::string("Title").c_str()); - msg->contentText = strdup(std::string("ContentText").c_str()); - msg->sourceName = strdup(std::string("OCF").c_str()); + msg->title = g_title; + msg->contentText = g_body; + msg->sourceName = g_sourceName; NSProviderSendSyncInfo(msg->messageId, NS_SYNC_READ); std::unique_lock< std::mutex > lock{ mutexForCondition }; @@ -318,9 +325,9 @@ TEST_F(NotificationProviderTest, ExpectCallbackSyncOnReadFromConsumer) NSMessage * msg = NSCreateMessage(); id = (int)msg->messageId; - msg->title = strdup(std::string("Title").c_str()); - msg->contentText = strdup(std::string("ContentText").c_str()); - msg->sourceName = strdup(std::string("OCF").c_str()); + msg->title = g_title; + msg->contentText = g_body; + msg->sourceName = g_sourceName; g_consumerSimul.syncToProvider(type, id, msg->providerId); std::unique_lock< std::mutex > lock{ mutexForCondition }; -- 2.7.4