null+****@clear*****
null+****@clear*****
2012年 2月 8日 (水) 17:50:58 JST
Kouhei Sutou 2012-02-08 17:50:58 +0900 (Wed, 08 Feb 2012) New Revision: 44075a3b8790cddd34ca0afde983d99dc2913638 Log: [test] fixed memory leaks. Modified files: test/unit/core/test-cast-table.c test/unit/core/test-hash-cursor.c test/unit/core/test-patricia-trie-search.c test/unit/core/test-table-patricia-trie-cursor.c test/unit/core/test-table-sort-geo.c test/unit/core/test-view-operations.c Modified: test/unit/core/test-cast-table.c (+5 -2) =================================================================== --- test/unit/core/test-cast-table.c 2012-02-08 17:36:33 +0900 (37f3dcb) +++ test/unit/core/test-cast-table.c 2012-02-08 17:50:58 +0900 (616e853) @@ -1,6 +1,6 @@ /* -*- c-basic-offset: 2; coding: utf-8 -*- */ /* - Copyright (C) 2010-2011 Kouhei Sutou <kou****@clear*****> + Copyright (C) 2010-2012 Kouhei Sutou <kou****@clear*****> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -31,12 +31,14 @@ static grn_ctx context; static grn_obj *database; static grn_obj src, dest; -static gchar *tmp_directory, *database_path; +static gchar *tmp_directory; static grn_id users, daijiro; static void setup_database(void) { + gchar *database_path; + tmp_directory = g_build_filename(grn_test_get_tmp_dir(), NULL); database_path = g_build_filename(tmp_directory, @@ -45,6 +47,7 @@ setup_database(void) g_mkdir_with_parents(tmp_directory, 0700); database = grn_db_create(&context, database_path, NULL); + g_free(database_path); } static void Modified: test/unit/core/test-hash-cursor.c (+5 -5) =================================================================== --- test/unit/core/test-hash-cursor.c 2012-02-08 17:36:33 +0900 (9e310f9) +++ test/unit/core/test-hash-cursor.c 2012-02-08 17:50:58 +0900 (af49367) @@ -1,6 +1,6 @@ /* -*- c-basic-offset: 2; coding: utf-8 -*- */ /* - Copyright (C) 2008-2009 Kouhei Sutou <kou****@cozmi*****> + Copyright (C) 2008-2012 Kouhei Sutou <kou****@clear*****> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -734,11 +734,11 @@ test_value(gconstpointer data) cut_assert_open_cursor(); while (grn_hash_cursor_next(context, cursor) != GRN_ID_NIL) { void *key; - gchar *null_terminated_key; + const gchar *null_terminated_key; int size; size = grn_hash_cursor_get_key(context, cursor, &key); - null_terminated_key = g_string_free(g_string_new_len(key, size), FALSE); + null_terminated_key = cut_take_strndup(key, size); if (g_str_equal(null_terminated_key, key2)) { grn_hash_cursor_set_value(context, cursor, value2, GRN_OBJ_SET); } else if (g_str_equal(null_terminated_key, key4)) { @@ -799,11 +799,11 @@ test_delete(gconstpointer data) cut_assert_open_cursor(); while (grn_hash_cursor_next(context, cursor) != GRN_ID_NIL) { void *key; - gchar *null_terminated_key; + const gchar *null_terminated_key; int size; size = grn_hash_cursor_get_key(context, cursor, &key); - null_terminated_key = g_string_free(g_string_new_len(key, size), FALSE); + null_terminated_key = cut_take_strndup(key, size); if (g_str_equal(null_terminated_key, key1) || g_str_equal(null_terminated_key, key5)) { grn_hash_cursor_delete(context, cursor, NULL); Modified: test/unit/core/test-patricia-trie-search.c (+2 -2) =================================================================== --- test/unit/core/test-patricia-trie-search.c 2012-02-08 17:36:33 +0900 (e87d6f9) +++ test/unit/core/test-patricia-trie-search.c 2012-02-08 17:50:58 +0900 (2f948d7) @@ -194,11 +194,11 @@ test_lcp_search(gconstpointer data) strlen(test_data->search_key)); if (test_data->expected_key) { int size; - gchar *null_terminated_key; + const gchar *null_terminated_key; grn_test_assert_not_nil(id); size = grn_pat_get_key(context, trie, id, key, sizeof(key)); - null_terminated_key = g_string_free(g_string_new_len(key, size), FALSE); + null_terminated_key = cut_take_strndup(key, size); cut_assert_equal_string(test_data->expected_key, null_terminated_key); } else { grn_test_assert_nil(id); Modified: test/unit/core/test-table-patricia-trie-cursor.c (+24 -24) =================================================================== --- test/unit/core/test-table-patricia-trie-cursor.c 2012-02-08 17:36:33 +0900 (76d742c) +++ test/unit/core/test-table-patricia-trie-cursor.c 2012-02-08 17:50:58 +0900 (a1f8a03) @@ -998,24 +998,24 @@ data_near_geo_point(void) NULL) ADD_DATA("no limit", - gcut_list_string_new(POINT(1, 2, 3, - 4, 5, 6), - POINT(1, 2, 3, - 7, 8, 9), - POINT(7, 8, 9, - 4, 5, 6), - POINT(88, 58, 58, - 178, 58, 58), - POINT(89, 59, 59, - 179, -59, -59), - POINT(89, 59, 59, - 179, 59, 59), - POINT(-89, -59, -59, - 179, 59, 59), - POINT(-89, -59, -59, - -179, -59, -59), - POINT(-88, -58, -58, - -178, -58, -58), + gcut_list_string_new(TAKEN_POINT(1, 2, 3, + 4, 5, 6), + TAKEN_POINT(1, 2, 3, + 7, 8, 9), + TAKEN_POINT(7, 8, 9, + 4, 5, 6), + TAKEN_POINT(88, 58, 58, + 178, 58, 58), + TAKEN_POINT(89, 59, 59, + 179, -59, -59), + TAKEN_POINT(89, 59, 59, + 179, 59, 59), + TAKEN_POINT(-89, -59, -59, + 179, 59, 59), + TAKEN_POINT(-89, -59, -59, + -179, -59, -59), + TAKEN_POINT(-88, -58, -58, + -178, -58, -58), NULL), 0, TAKEN_POINT(0, 0, 0, @@ -1023,12 +1023,12 @@ data_near_geo_point(void) 0, -1, 0); ADD_DATA("min-size", - gcut_list_string_new(POINT(1, 2, 3, - 4, 5, 6), - POINT(1, 2, 3, - 7, 8, 9), - POINT(7, 8, 9, - 4, 5, 6), + gcut_list_string_new(TAKEN_POINT(1, 2, 3, + 4, 5, 6), + TAKEN_POINT(1, 2, 3, + 7, 8, 9), + TAKEN_POINT(7, 8, 9, + 4, 5, 6), NULL), 1, TAKEN_POINT(0, 0, 0, Modified: test/unit/core/test-table-sort-geo.c (+56 -43) =================================================================== --- test/unit/core/test-table-sort-geo.c 2012-02-08 17:36:33 +0900 (83049d0) +++ test/unit/core/test-table-sort-geo.c 2012-02-08 17:50:58 +0900 (9bde57c) @@ -1,6 +1,6 @@ /* -*- c-basic-offset: 2; coding: utf-8 -*- */ /* - Copyright (C) 2010-2011 Kouhei Sutou <kou****@clear*****> + Copyright (C) 2010-2012 Kouhei Sutou <kou****@clear*****> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -45,6 +45,19 @@ COORDINATE(latitude_hours, latitude_minutes, latitude_seconds), \ COORDINATE(longitude_hours, longitude_minutes, longitude_seconds)) +#define TAKEN_INSPECTED_POINT(latitude_hours, \ + latitude_minutes, \ + latitude_seconds, \ + longitude_hours, \ + longitude_minutes, \ + longitude_seconds) \ + cut_take_string(INSPECTED_POINT(latitude_hours, \ + latitude_minutes, \ + latitude_seconds, \ + longitude_hours, \ + longitude_minutes, \ + longitude_seconds)) + void data_near_geo_point(void); void test_near_geo_point(gpointer data); @@ -174,60 +187,60 @@ data_near_geo_point(void) NULL) ADD_DATA("no limit", - gcut_list_string_new(INSPECTED_POINT(-1, -1, -1, - 0, 0, 0), - INSPECTED_POINT(1, 0, 0, - 1, 0, 0), - INSPECTED_POINT(-1, 0, 0, - 1, 1, 1), - INSPECTED_POINT(1, 1, 0, - 1, 1, 0), - INSPECTED_POINT(1, 1, 1, - 1, 1, 1), - INSPECTED_POINT(1, 1, 10, - -1, -1, -1), - INSPECTED_POINT(-1, -2, -1, - -1, -1, -1), - INSPECTED_POINT(90, 0, 0, - 0, 0, 0), - INSPECTED_POINT(-90, 0, 0, - 1, 0, 0), - INSPECTED_POINT(-2, -1, -1, - -179, -59, -59), - INSPECTED_POINT(2, 1, 1, - 180, 0, 0), - INSPECTED_POINT(1, 2, 1, - -179, -59, -59), - INSPECTED_POINT(-1, -1, -1, - 180, 0, 0), - INSPECTED_POINT(0, 0, 0, - -179, -59, -59), - INSPECTED_POINT(0, 0, 0, - 180, 0, 0), + gcut_list_string_new(TAKEN_INSPECTED_POINT(-1, -1, -1, + 0, 0, 0), + TAKEN_INSPECTED_POINT(1, 0, 0, + 1, 0, 0), + TAKEN_INSPECTED_POINT(-1, 0, 0, + 1, 1, 1), + TAKEN_INSPECTED_POINT(1, 1, 0, + 1, 1, 0), + TAKEN_INSPECTED_POINT(1, 1, 1, + 1, 1, 1), + TAKEN_INSPECTED_POINT(1, 1, 10, + -1, -1, -1), + TAKEN_INSPECTED_POINT(-1, -2, -1, + -1, -1, -1), + TAKEN_INSPECTED_POINT(90, 0, 0, + 0, 0, 0), + TAKEN_INSPECTED_POINT(-90, 0, 0, + 1, 0, 0), + TAKEN_INSPECTED_POINT(-2, -1, -1, + -179, -59, -59), + TAKEN_INSPECTED_POINT(2, 1, 1, + 180, 0, 0), + TAKEN_INSPECTED_POINT(1, 2, 1, + -179, -59, -59), + TAKEN_INSPECTED_POINT(-1, -1, -1, + 180, 0, 0), + TAKEN_INSPECTED_POINT(0, 0, 0, + -179, -59, -59), + TAKEN_INSPECTED_POINT(0, 0, 0, + 180, 0, 0), NULL), TAKEN_POINT(0, 0, 0, 0, 0, 0), 0, -1); ADD_DATA("limit", - gcut_list_string_new(INSPECTED_POINT(-1, -1, -1, - 0, 0, 0), - INSPECTED_POINT(1, 0, 0, - 1, 0, 0), - INSPECTED_POINT(-1, 0, 0, - 1, 1, 1), + gcut_list_string_new(TAKEN_INSPECTED_POINT(-1, -1, -1, + 0, 0, 0), + TAKEN_INSPECTED_POINT(1, 0, 0, + 1, 0, 0), + TAKEN_INSPECTED_POINT(-1, 0, 0, + 1, 1, 1), NULL), TAKEN_POINT(0, 0, 0, 0, 0, 0), 0, 3); ADD_DATA("offset - limit", - gcut_list_string_new(INSPECTED_POINT(-1, 0, 0, - 1, 1, 1), - INSPECTED_POINT(1, 1, 0, - 1, 1, 0), - INSPECTED_POINT(1, 1, 1, - 1, 1, 1), + gcut_list_string_new(TAKEN_INSPECTED_POINT(-1, 0, 0, + 1, 1, 1), + TAKEN_INSPECTED_POINT(1, 1, 0, + 1, 1, 0), + TAKEN_INSPECTED_POINT(1, 1, 1, + 1, 1, 1), NULL), TAKEN_POINT(0, 0, 0, 0, 0, 0), Modified: test/unit/core/test-view-operations.c (+3 -1) =================================================================== --- test/unit/core/test-view-operations.c 2012-02-08 17:36:33 +0900 (51c69eb) +++ test/unit/core/test-view-operations.c 2012-02-08 17:50:58 +0900 (2cf115f) @@ -1,6 +1,6 @@ /* -*- c-basic-offset: 2; coding: utf-8 -*- */ /* - Copyright (C) 2010 Kouhei Sutou <kou****@clear*****> + Copyright (C) 2010-2012 Kouhei Sutou <kou****@clear*****> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -178,6 +178,7 @@ test_sort(void) limit = 2; n_records = grn_table_sort(context, entries, 0, limit, result, keys, sizeof(keys[0]) / sizeof(keys)); + grn_obj_unlink(context, keys[0].key); grn_test_assert_equal_view(context, gcut_take_new_list_string("yu", "taro", @@ -208,6 +209,7 @@ test_sort_offset(void) limit = 2; n_records = grn_table_sort(context, entries, offset, limit, result, keys, sizeof(keys[0]) / sizeof(keys)); + grn_obj_unlink(context, keys[0].key); grn_test_assert_equal_view(context, gcut_take_new_list_string("taro", "pochi",