From: hyunho Date: Tue, 21 Jan 2020 02:01:18 +0000 (+0900) Subject: Fix memory leak X-Git-Tag: submit/tizen_5.5/20200131.035153~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6a654b961ffdf351b0e424cd31b33aab96c17605;p=platform%2Fcore%2Fappfw%2Fcomponent-based-application.git Fix memory leak Change-Id: I1ee5568748fbd9ba36fc6625296040b77fd50554 Signed-off-by: hyunho --- diff --git a/component_based/base/api/base_frame_component.h b/component_based/base/api/base_frame_component.h index bf5cc1c..9f2b868 100644 --- a/component_based/base/api/base_frame_component.h +++ b/component_based/base/api/base_frame_component.h @@ -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( diff --git a/component_based/base/stub.cc b/component_based/base/stub.cc index 25735fd..1d95b29 100644 --- a/component_based/base/stub.cc +++ b/component_based/base/stub.cc @@ -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) { diff --git a/unit_tests/src/base/test_base_frame_stub.cc b/unit_tests/src/base/test_base_frame_stub.cc index fdd1863..46f2853 100644 --- a/unit_tests/src/base/test_base_frame_stub.cc +++ b/unit_tests/src/base/test_base_frame_stub.cc @@ -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)