Fix memory leak 91/220191/1
authormk5004.lee <mk5004.lee@samsung.com>
Mon, 16 Dec 2019 02:38:34 +0000 (11:38 +0900)
committermk5004.lee <mk5004.lee@samsung.com>
Mon, 16 Dec 2019 02:38:34 +0000 (11:38 +0900)
Change-Id: I87a84de5a2864c77e19e9a8aac0f9828997de35d
Signed-off-by: mk5004.lee <mk5004.lee@samsung.com>
notification-ex/group_item.cc
unittest/src/test_abstract_item.cc

index 3407938..a222587 100644 (file)
@@ -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() {
index b922d85..58b5d1c 100644 (file)
@@ -17,6 +17,7 @@
 #include <gtest/gtest.h>
 #include <gmock/gmock.h>
 #include <app_control.h>
+#include <app_common.h>
 
 #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<GroupItem>("test_group");
   auto item = std::make_shared<ButtonItem>("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