Fix memory leak 58/222858/2
authorhyunho <hhstark.kang@samsung.com>
Tue, 21 Jan 2020 02:01:18 +0000 (11:01 +0900)
committerhyunho <hhstark.kang@samsung.com>
Tue, 21 Jan 2020 02:07:08 +0000 (11:07 +0900)
Change-Id: I1ee5568748fbd9ba36fc6625296040b77fd50554
Signed-off-by: hyunho <hhstark.kang@samsung.com>
component_based/base/api/base_frame_component.h
component_based/base/stub.cc
unit_tests/src/base/test_base_frame_stub.cc

index bf5cc1c5e26ec7128a70130144defedfe4435ba8..9f2b868294c6b148709f26a17f0b45f5880c7674 100644 (file)
@@ -29,6 +29,7 @@ extern "C" {
 typedef struct frame_window_s *frame_window_h;
 
 int base_frame_create_window(frame_window_h *handle, int id, void *raw);
+int base_frame_destroy_window(frame_window_h handle);
 int base_frame_window_get_id(frame_window_h handle, int *id);
 int base_frame_window_get_raw(frame_window_h handle, void **raw);
 int base_frame_get_display_status(
index 25735fd9310d83cdc38f927bb591ebc3f16e14c6..1d95b298842442d787a7caad2c3e7be14942bf00 100644 (file)
@@ -292,6 +292,7 @@ class StubFrameComponent : public component_based::FrameComponent {
 
     component_based::FrameWindow* frm_win =
         new (std::nothrow) component_based::FrameWindow(win->id, win->raw);
+    base_frame_destroy_window(win);
     if (frm_win == nullptr) {
       LOGE("Out of memory");
       return nullptr;
@@ -525,6 +526,15 @@ extern "C" EXPORT_API int base_frame_create_window(frame_window_h* handle,
   return COMPONENT_ERROR_NONE;
 }
 
+extern "C" EXPORT_API int base_frame_destroy_window(frame_window_h handle) {
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return COMPONENT_ERROR_INVALID_PARAMETER;
+  }
+  free(handle);
+  return COMPONENT_ERROR_NONE;
+}
+
 extern "C" EXPORT_API int base_frame_window_get_id(frame_window_h handle,
     int* id) {
   if (handle == nullptr || id == nullptr) {
index fdd186381bebaf6b1e5c3ace3920278759ad5e4d..46f285310e93e14d139e2a99086527f80b1b5238 100644 (file)
@@ -551,6 +551,7 @@ TEST_F(BaseStubTest, base_frame_create_window)
   int ret = base_frame_create_window(
       &handle, 1, nullptr);
   EXPECT_EQ(COMPONENT_ERROR_NONE, ret);
+  base_frame_destroy_window(handle);
 }
 
 TEST_F(BaseStubTest, base_frame_window_get_id)
@@ -564,6 +565,7 @@ TEST_F(BaseStubTest, base_frame_window_get_id)
   ret = base_frame_window_get_id(handle, &id);
   EXPECT_EQ(COMPONENT_ERROR_NONE, ret);
   EXPECT_EQ(id, 1);
+  base_frame_destroy_window(handle);
 }
 
 TEST_F(BaseStubTest, base_frame_window_get_raw)
@@ -578,6 +580,7 @@ TEST_F(BaseStubTest, base_frame_window_get_raw)
   ret = base_frame_window_get_raw(handle, &raw);
   EXPECT_EQ(COMPONENT_ERROR_NONE, ret);
   free(test);
+  base_frame_destroy_window(handle);
 }
 
 void __app_init_cb(int argc, char** argv, void *user_data)