fix memory leak 59/61259/4 accepted/tizen/common/20160307.154251 accepted/tizen/ivi/20160307.110344 accepted/tizen/mobile/20160307.110257 accepted/tizen/tv/20160307.110316 accepted/tizen/wearable/20160307.110331 submit/tizen/20160307.072409
authorJongkyu Koo <jk.koo@samsung.com>
Mon, 7 Mar 2016 05:22:35 +0000 (14:22 +0900)
committerJongkyu Koo <jk.koo@samsung.com>
Mon, 7 Mar 2016 07:19:42 +0000 (23:19 -0800)
Change-Id: I54cece2f989779c6fc48b0997c9026e21cdeb221
Signed-off-by: Jongkyu Koo <jk.koo@samsung.com>
server/ctsvc_server_person.c
test/test_main.c
test/test_main.h
test/test_query.c

index 7a504ec..720bc80 100644 (file)
@@ -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;
        }
index e532542..0dcef56 100644 (file)
@@ -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;
index 9ac380b..1ddfee2 100644 (file)
@@ -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__ */
index fdcc0cc..11020cc 100644 (file)
@@ -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;