Fix memory leak 12/178412/4
authormk5004.lee <mk5004.lee@samsung.com>
Thu, 10 May 2018 02:36:48 +0000 (11:36 +0900)
committermk5004.lee <mk5004.lee@samsung.com>
Thu, 10 May 2018 05:39:39 +0000 (14:39 +0900)
Change-Id: If314a1b0692fc5eafbbcc4c8fce73347728371cd
Signed-off-by: mk5004.lee <mk5004.lee@samsung.com>
unittest/src/test_editables_container.cc
unittest/src/test_editor.cc
unittest/src/test_received_editable.cc
unittest/src/test_tools.cc
watchface-complication/complication.cc
watchface-complication/editables-container.cc
watchface-editor/editables-editor.cc

index 6d2f75f..672439c 100644 (file)
@@ -71,6 +71,8 @@ class EC : public ::testing::Test {
 
     delete candidate1;
     delete candidate2;
+    bundle_free(data);
+    free(raw_data);
   }
   virtual void TearDown() {
     delete received;
@@ -102,18 +104,20 @@ TEST_F(EC, AddRemove)
   bundle_add_str(data, "CUR_DATA_IDX", std::to_string(0).c_str());
   bundle_add_str(data, "NAME", "sample");
   bundle_add_str(data, "EDITABLE_ID", std::to_string(0).c_str());
-  bundle_encode(data, &raw_data, &len);
 
   array.get()[0] = candidate1->ToString();
   array.get()[1] = candidate2->ToString();
-
   bundle_add_str_array(data, "CANDIDATES_LIST", array.get(), 2);
 
+  bundle_encode(data, &raw_data, &len);
+
   ReceivedEditable* re = new ReceivedEditable(std::string(reinterpret_cast<char*>(raw_data)));
   std::shared_ptr<IEditable> ed = static_cast<std::shared_ptr<IEditable>>(re);
 
   delete candidate1;
   delete candidate2;
+  bundle_free(data);
+  free(raw_data);
 
   EXPECT_EQ(EC::container->Add(ed, 1), 0);
   EXPECT_EQ(EC::container->Remove(ed), 0);
@@ -157,7 +161,8 @@ TEST_F(EC, GetData)
   EXPECT_EQ(id, 0);
 
   EXPECT_EQ(watchface_editable_get_geometry(EC::received, &geo), 0);
-  EXPECT_EQ(watchface_editable_get_editable_name(EC::received, &get_editable_name), 0);
+  watchface_editable_geometry_destroy(geo);
 
+  EXPECT_EQ(watchface_editable_get_editable_name(EC::received, &get_editable_name), 0);
   free(get_editable_name);
 }
index 744487b..5e16532 100644 (file)
@@ -71,7 +71,10 @@ TEST_F(WE, EditPreview)
   ReceivedEditable* re = new ReceivedEditable(std::string(reinterpret_cast<char*>(raw_data)));
   IEditable* ed = static_cast<IEditable*>(re);
   EXPECT_EQ(WE::editor->EditPreview(*ed, cur_data_idx), WATCHFACE_COMPLICATION_ERROR_EDIT_NOT_READY);
+
   delete re;
+  bundle_free(data);
+  free(raw_data);
 }
 
 TEST_F(WE, NotifyEditReady)
@@ -118,6 +121,8 @@ class WEL : public ::testing::Test {
 
     delete candidate1;
     delete candidate2;
+    bundle_free(data);
+    free(raw_data);
   }
   virtual void TearDown(){
     delete received;
index 2dc5b0a..2a880c4 100644 (file)
@@ -66,6 +66,7 @@ class RE : public ::testing::Test {
 
     delete candidate1;
     delete candidate2;
+    free(raw_data);
   }
   virtual void TearDown() {
     delete received;
index d927a02..9709d2b 100644 (file)
@@ -63,6 +63,7 @@ TEST_F(BUNDLE, Create2)
   EXPECT_NE(b, nullptr);
 
   bundle_free(data);
+  free(raw_data);
   delete b;
 }
 
index 513a389..dee89f0 100644 (file)
@@ -107,6 +107,9 @@ void Complication::Impl::OnSignal(GDBusConnection* connection,
           ComplicationConnector::CompNotifyDataUpdate)) == 0) {
     parent_->OnNotifyDataUpdate();
   }
+
+  if (raw)
+    free(raw);
 }
 
 int Complication::Impl::FindCandidateDataIdx(std::string provider_id, int type) {
@@ -595,6 +598,7 @@ int Complication::Impl::AddCandidate(std::string provider_id, int type) {
   bundle_add_str(data, provider_type_key_.c_str(),
       std::to_string(type).c_str());
   candidates_list_.emplace_back(new Bundle(data));
+  bundle_free(data);
 
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
index cb3ca3e..2a05be7 100644 (file)
@@ -175,6 +175,8 @@ int EditablesContainer::RequestEdit() {
     bundle_add(ed, "SHAPE_TYPE", std::to_string(type).c_str());
     bundle_encode(ed, &str_raw, &str_len);
     list_arr.get()[list_idx++] = reinterpret_cast<char*>(str_raw);
+
+    bundle_free(ed);
   }
 
   bundle* container = bundle_create();
index de7b9bd..64b4b6a 100644 (file)
@@ -84,6 +84,7 @@ void EditablesEditor::Impl::OnSignal(GDBusConnection* connection,
                   new ReceivedEditable(std::string(str_arr[i]))));
     }
     parent_->OnRequestEdit(std::string(appid), std::move(e_list));
+    bundle_free(data);
   } else if (signal_name.compare(
       ComplicationConnector::GetInst().GetCmdStr(
           ComplicationConnector::SetupReply)) == 0) {
@@ -92,6 +93,9 @@ void EditablesEditor::Impl::OnSignal(GDBusConnection* connection,
     g_variant_get(parameters, "(i&s)", &edit_id, &raw_str);
     parent_->OnSetupReply(edit_id, std::unique_ptr<Bundle>(new Bundle(std::string(raw_str))));
   }
+
+  if (raw)
+    free(raw);
 }
 
 void EditablesEditor::OnSetupReply(int editable_id, std::unique_ptr<Bundle> context) {