From a9f985866890106b44de386f76f6ce3fd2050acc Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Mon, 22 Apr 2019 11:29:37 +0900 Subject: [PATCH] Fix memory leak for unit_tests Change-Id: I4c7071117f83181358576a35987ed104b08e9fd1 Signed-off-by: Inkyun Kil --- unit_tests/src/app_control_unittest.cc | 28 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/unit_tests/src/app_control_unittest.cc b/unit_tests/src/app_control_unittest.cc index 059cfef..8cef8bc 100644 --- a/unit_tests/src/app_control_unittest.cc +++ b/unit_tests/src/app_control_unittest.cc @@ -82,18 +82,22 @@ class AppControlTest : public testing::Test { */ TEST_F(AppControlTest, app_control_create_from_uri_handle_p) { app_control_h app_control; - char *uri; - char *query_tag; int r = app_control_create_from_uri_handle(&app_control, uri_); EXPECT_EQ(r, APP_CONTROL_ERROR_NONE); - r = app_control_get_uri(app_control, &uri); + std::unique_ptr::type, + decltype(app_control_destroy)*> handle(app_control, app_control_destroy); + + char *v; + r = app_control_get_uri(handle.get(), &v); EXPECT_EQ(r, APP_CONTROL_ERROR_NONE); - EXPECT_STREQ(uri, EXAM_URI1); + auto value = std::unique_ptr(v, std::free); + EXPECT_EQ(std::string(value.get()), EXAM_URI1); - r = app_control_get_extra_data(app_control, "tag", &query_tag); + r = app_control_get_extra_data(handle.get(), "tag", &v); EXPECT_EQ(r, APP_CONTROL_ERROR_NONE); - EXPECT_STREQ(query_tag, "networking"); + value = std::unique_ptr(v, std::free); + EXPECT_EQ(std::string(value.get()), "networking"); } /* @@ -103,14 +107,18 @@ TEST_F(AppControlTest, app_control_create_from_uri_handle_p) { */ TEST_F(AppControlTest, app_control_set_uri_by_handle_p) { app_control_h app_control; - char *uri; int r = app_control_create(&app_control); EXPECT_EQ(r, APP_CONTROL_URI_ERROR_NONE); - r = app_control_set_uri_by_handle(app_control, uri_); + std::unique_ptr::type, + decltype(app_control_destroy)*> handle(app_control, app_control_destroy); + + r = app_control_set_uri_by_handle(handle.get(), uri_); EXPECT_EQ(r, APP_CONTROL_URI_ERROR_NONE); - r = app_control_get_uri(app_control, &uri); + char *v; + r = app_control_get_uri(handle.get(), &v); EXPECT_EQ(r, APP_CONTROL_ERROR_NONE); - EXPECT_STREQ(uri, EXAM_URI1); + auto value = std::unique_ptr(v, std::free); + EXPECT_EQ(std::string(value.get()), EXAM_URI1); } -- 2.34.1