From 90c2ebf9efdc8e37438eb7c10efa1297c2076e93 Mon Sep 17 00:00:00 2001 From: "mk5004.lee" Date: Mon, 16 Dec 2019 11:38:34 +0900 Subject: [PATCH] Fix memory leak Change-Id: I87a84de5a2864c77e19e9a8aac0f9828997de35d Signed-off-by: mk5004.lee --- notification-ex/group_item.cc | 6 ++++-- unittest/src/test_abstract_item.cc | 10 +++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/notification-ex/group_item.cc b/notification-ex/group_item.cc index 34079389..a222587c 100644 --- a/notification-ex/group_item.cc +++ b/notification-ex/group_item.cc @@ -56,10 +56,12 @@ GroupItem::Impl::Impl(GroupItem* parent) LOGI("GroupItem created"); char* name; int ret = app_get_name(&name); - if (ret != APP_ERROR_NONE) + if (ret != APP_ERROR_NONE) { app_label_ = util::GetAppId(); - else + } else { app_label_ = string(name); + free(name); + } } GroupItem::~GroupItem() { diff --git a/unittest/src/test_abstract_item.cc b/unittest/src/test_abstract_item.cc index b922d854..58b5d1c6 100644 --- a/unittest/src/test_abstract_item.cc +++ b/unittest/src/test_abstract_item.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include "notification-ex/item_inflator.h" #include "notification-ex/app_control_action.h" @@ -292,7 +293,14 @@ TEST_F(AbstractItemTest, SetGetOnGoingState) { ASSERT_EQ(item.GetOnGoingState(), true); } +int __fake_app_get_name(char** app_name) { + *app_name = strdup("unittest_appname"); + return 0; +} + TEST_F(AbstractItemTest, SetGetFindMainType) { + app_get_name_fake.custom_fake = __fake_app_get_name; + auto root = std::make_shared("test_group"); auto item = std::make_shared("test_id", "title"); root->AddChild(item); @@ -313,4 +321,4 @@ TEST_F(AbstractItemTest, SetInvalidMainType) { EXPECT_FALSE(ret); } -} // namespace \ No newline at end of file +} // namespace -- 2.34.1