From 39b88d4e37ffe12b775f7932a35cb3819486c717 Mon Sep 17 00:00:00 2001 From: Sung-hun Kim Date: Mon, 19 Sep 2022 13:42:34 +0900 Subject: [PATCH] resource-monitor-tests: Prevent possible memory leaks Change-Id: I9ff9c4bd7ef970ca1541c756fd1b11c5506980f9 Signed-off-by: Sung-hun Kim --- tests/integration-test/resource-monitor-tests.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/integration-test/resource-monitor-tests.cpp b/tests/integration-test/resource-monitor-tests.cpp index f588989..f10237a 100644 --- a/tests/integration-test/resource-monitor-tests.cpp +++ b/tests/integration-test/resource-monitor-tests.cpp @@ -785,6 +785,7 @@ static int __pass_resource_monitor_get_value(int mon_id, int res_id, int num_att int32_t *array = NULL; ret = pass_resource_monitor_get_array_int(mon_id, res_id, attrs[i].attr_id, &array, &length); + free(array); EXPECT_EQ(ret, 0); break; } @@ -793,6 +794,7 @@ static int __pass_resource_monitor_get_value(int mon_id, int res_id, int num_att int64_t *array = NULL;; ret = pass_resource_monitor_get_array_int64(mon_id, res_id, attrs[i].attr_id, &array, &length); + free(array); EXPECT_EQ(ret, 0); break; } @@ -801,6 +803,7 @@ static int __pass_resource_monitor_get_value(int mon_id, int res_id, int num_att u_int32_t *array = NULL; ret = pass_resource_monitor_get_array_uint(mon_id, res_id, attrs[i].attr_id, &array, &length); + free(array); EXPECT_EQ(ret, 0); break; } @@ -809,6 +812,7 @@ static int __pass_resource_monitor_get_value(int mon_id, int res_id, int num_att u_int64_t *array = NULL; ret = pass_resource_monitor_get_array_uint64(mon_id, res_id, attrs[i].attr_id, &array, &length); + free(array); EXPECT_EQ(ret, 0); break; } @@ -817,6 +821,7 @@ static int __pass_resource_monitor_get_value(int mon_id, int res_id, int num_att double *array = NULL; ret = pass_resource_monitor_get_array_double(mon_id, res_id, attrs[i].attr_id, &array, &length); + free(array); EXPECT_EQ(ret, 0); break; } @@ -825,6 +830,9 @@ static int __pass_resource_monitor_get_value(int mon_id, int res_id, int num_att char **array = NULL; ret = pass_resource_monitor_get_array_string(mon_id, res_id, attrs[i].attr_id, &array, &length); + for (int i = 0; i < length; i++) + g_free(array[i]); + free(array); EXPECT_EQ(ret, 0); break; } -- 2.7.4