From 89e6c492db927211b3ac88dd391bb9c0bfbf3227 Mon Sep 17 00:00:00 2001 From: Jongkyu Koo Date: Mon, 7 Mar 2016 14:22:35 +0900 Subject: [PATCH] fix memory leak Change-Id: I54cece2f989779c6fc48b0997c9026e21cdeb221 Signed-off-by: Jongkyu Koo --- server/ctsvc_server_person.c | 2 ++ test/test_main.c | 13 +++++++++---- test/test_main.h | 2 +- test/test_query.c | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/server/ctsvc_server_person.c b/server/ctsvc_server_person.c index 7a504ec..720bc80 100644 --- a/server/ctsvc_server_person.c +++ b/server/ctsvc_server_person.c @@ -1773,6 +1773,7 @@ int ctsvc_person_get_aggregation_suggestions(int person_id, int limit, contacts_ if (0 == sub_len) { *out_list = NULL; + free(sub_query); WARN("no numbers, emails, names for query"); return CONTACTS_ERROR_NO_DATA; } @@ -1827,6 +1828,7 @@ int ctsvc_person_get_aggregation_suggestions(int person_id, int limit, contacts_ if (0 == sub_len) { *out_list = NULL; + free(sub_query); WARN("no person_id for aggregation suggestions"); return CONTACTS_ERROR_NO_DATA; } diff --git a/test/test_main.c b/test/test_main.c index e532542..0dcef56 100644 --- a/test/test_main.c +++ b/test/test_main.c @@ -45,14 +45,18 @@ static const func _func[] = { _print_errors, }; -bool test_main_is_selected(int argc, char **argv, int depth, const func _func[]) +bool test_main_is_selected(int argc, char **argv, int depth, const func test_func[], int count) { if (argc <= depth) { return false; } int select = atoi(argv[depth]); - _func[select](argc, argv); + + if (0 <= select && select < count) + test_func[select](argc, argv); + else + ERR("no test func (%d)", select); return true; } @@ -74,11 +78,12 @@ int main(int argc, char **argv) ENTER(); DBG("argc(%d)", argc); - if (true == test_main_is_selected(argc, argv, 1, _func)) + + int count = sizeof(_func) / sizeof(func); + if (true == test_main_is_selected(argc, argv, 1, _func, count)) return 0; int i = 0; - int count = sizeof(_func) / sizeof(func); for (i = 0; i < count; i++) { if (_func[i](argc, argv) < 0) break; diff --git a/test/test_main.h b/test/test_main.h index 9ac380b..1ddfee2 100644 --- a/test/test_main.h +++ b/test/test_main.h @@ -18,6 +18,6 @@ #define __TEST_MAIN_H__ typedef int (*func)(int argc, char **argv); -bool test_main_is_selected(int argc, char **argv, int step, const func _func[]); +bool test_main_is_selected(int argc, char **argv, int step, const func test_func[], int count); #endif /* __TEST_MAIN_H__ */ diff --git a/test/test_query.c b/test/test_query.c index fdcc0cc..11020cc 100644 --- a/test/test_query.c +++ b/test/test_query.c @@ -322,11 +322,11 @@ int test_query(int argc, char **argv) { ENTER(); - if (true == test_main_is_selected(argc, argv, 2, _func)) + int count = sizeof(_func) / sizeof(func); + if (true == test_main_is_selected(argc, argv, 2, _func, count)) return 0; int i = 0; - int count = sizeof(_func) / sizeof(func); for (i = 0; i < count; i++) { if (_func[i](argc, argv) < 0) break; -- 2.7.4