From beb0f9c15058e2249ffed73747f11298e6949b84 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 24 Aug 2012 20:43:54 -0400 Subject: [PATCH] gio/tests: fix leaks https://bugzilla.gnome.org/show_bug.cgi?id=682560 --- gio/tests/appinfo.c | 2 ++ gio/tests/contexts.c | 13 ++++++++++++- gio/tests/converter-stream.c | 1 + gio/tests/file.c | 5 ++++- gio/tests/live-g-file.c | 21 +++++++++++++++++---- gio/tests/memory-input-stream.c | 3 +++ gio/tests/mimeapps.c | 1 + gio/tests/network-address.c | 1 + gio/tests/network-monitor.c | 26 +++++++++++++++++++++++++- gio/tests/proxy-test.c | 36 +++++++++++++++++++++++++++--------- gio/tests/unix-streams.c | 1 + 11 files changed, 94 insertions(+), 16 deletions(-) diff --git a/gio/tests/appinfo.c b/gio/tests/appinfo.c index 7e82173..3cbd0f1 100644 --- a/gio/tests/appinfo.c +++ b/gio/tests/appinfo.c @@ -38,6 +38,8 @@ test_launch (void) g_assert (g_app_info_launch_uris (appinfo, l, NULL, &error)); g_assert_no_error (error); g_list_free (l); + + g_object_unref (appinfo); } static void diff --git a/gio/tests/contexts.c b/gio/tests/contexts.c index aa8bdd4..fd5cd1a 100644 --- a/gio/tests/contexts.c +++ b/gio/tests/contexts.c @@ -119,6 +119,9 @@ test1_thread (gpointer user_data) g_cond_signal (&test1_cond); g_mutex_unlock (&test1_mutex); + g_main_context_pop_thread_default (context); + g_main_context_unref (context); + return NULL; } @@ -164,6 +167,9 @@ test_context_independence (void) g_source_remove (default_timeout); g_source_destroy (thread_default_timeout); g_source_unref (thread_default_timeout); + + g_main_context_pop_thread_default (context); + g_main_context_unref (context); } static gboolean @@ -177,6 +183,7 @@ int main (int argc, char **argv) { GError *error = NULL; + int ret; g_type_init (); g_test_init (&argc, &argv, NULL); @@ -188,5 +195,9 @@ main (int argc, char **argv) g_test_add_func ("/gio/contexts/thread-independence", test_thread_independence); g_test_add_func ("/gio/contexts/context-independence", test_context_independence); - return g_test_run(); + ret = g_test_run(); + + g_free (test_file_buffer); + + return ret; } diff --git a/gio/tests/converter-stream.c b/gio/tests/converter-stream.c index 4404fb8..fc9c896 100644 --- a/gio/tests/converter-stream.c +++ b/gio/tests/converter-stream.c @@ -1138,6 +1138,7 @@ test_truncation (gconstpointer data) g_output_stream_splice (ostream2, cistream1, 0, NULL, &error); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT); + g_error_free (error); g_object_unref (istream1); g_object_unref (decompressor); diff --git a/gio/tests/file.c b/gio/tests/file.c index c707d0d..f19b87d 100644 --- a/gio/tests/file.c +++ b/gio/tests/file.c @@ -122,8 +122,11 @@ monitor_changed (GFileMonitor *monitor, gpointer user_data) { CreateDeleteData *data = user_data; + gchar *path; - g_assert_cmpstr (data->monitor_path, ==, g_file_get_path (file)); + path = g_file_get_path (file); + g_assert_cmpstr (data->monitor_path, ==, path); + g_free (path); if (event_type == G_FILE_MONITOR_EVENT_CREATED) data->monitor_created++; diff --git a/gio/tests/live-g-file.c b/gio/tests/live-g-file.c index e764144..32b600b 100644 --- a/gio/tests/live-g-file.c +++ b/gio/tests/live-g-file.c @@ -431,6 +431,7 @@ test_initial_structure (gconstpointer test_data) test_attributes (item, info); g_object_unref (child); + g_object_unref (info); } /* read and test the pattern file */ @@ -447,6 +448,7 @@ test_initial_structure (gconstpointer test_data) g_assert (info != NULL); size = g_file_info_get_size (info); g_assert_cmpint (size, ==, PATTERN_FILE_SIZE); + g_object_unref (info); error = NULL; ins = g_file_read (child, NULL, &error); @@ -538,6 +540,9 @@ traverse_recurse_dirs (GFile * parent, GFile * root) g_object_unref (descend); error = NULL; + g_object_unref (info); + g_free (relative_path); + info = g_file_enumerator_next_file (enumerator, NULL, &error); } g_assert_no_error (error); @@ -891,6 +896,7 @@ test_create (gconstpointer test_data) error->code, error->message); g_assert_cmpint (res, ==, TRUE); g_assert_no_error (error); + g_object_unref (os); } g_object_unref (child); } @@ -961,6 +967,7 @@ test_open (gconstpointer test_data) &error); g_assert_cmpint (res, ==, TRUE); g_assert_no_error (error); + g_object_unref (input_stream); } g_object_unref (child); } @@ -977,6 +984,7 @@ test_delete (gconstpointer test_data) GError *error; guint i; struct StructureItem item; + gchar *path; g_assert (test_data != NULL); log ("\n"); @@ -1000,8 +1008,10 @@ test_delete (gconstpointer test_data) g_assert (child != NULL); /* we don't care about result here */ - log (" Deleting %s, path = %s\n", item.filename, - g_file_get_path (child)); + path = g_file_get_path (child); + log (" Deleting %s, path = %s\n", item.filename, path); + g_free (path); + error = NULL; if ((item.extra_flags & TEST_DELETE_NORMAL) == TEST_DELETE_NORMAL) res = g_file_delete (child, NULL, &error); @@ -1138,11 +1148,10 @@ cleanup_dir_recurse (GFile *parent, GFile *root) g_assert (root != NULL); - error = NULL; enumerator = g_file_enumerate_children (parent, "*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, - &error); + NULL); if (! enumerator) return; @@ -1154,6 +1163,7 @@ cleanup_dir_recurse (GFile *parent, GFile *root) g_assert (descend != NULL); relative_path = g_file_get_relative_path (root, descend); g_assert (relative_path != NULL); + g_free (relative_path); log (" deleting '%s'\n", g_file_info_get_display_name (info)); @@ -1166,6 +1176,8 @@ cleanup_dir_recurse (GFile *parent, GFile *root) g_object_unref (descend); error = NULL; + g_object_unref (info); + info = g_file_enumerator_next_file (enumerator, NULL, &error); } g_assert_no_error (error); @@ -1263,6 +1275,7 @@ main (int argc, char *argv[]) return g_test_run (); } + g_option_context_free (context); /* Write test - clean target directory first */ /* this can be also considered as a test - enumerate + delete */ diff --git a/gio/tests/memory-input-stream.c b/gio/tests/memory-input-stream.c index 39079cb..d012125 100644 --- a/gio/tests/memory-input-stream.c +++ b/gio/tests/memory-input-stream.c @@ -217,6 +217,9 @@ test_read_bytes (void) data = g_bytes_get_data (bytes, &size); g_assert_cmpint (size, ==, 26); g_assert (strncmp (data, data1, 26) == 0); + + g_bytes_unref (bytes); + g_object_unref (stream); } int diff --git a/gio/tests/mimeapps.c b/gio/tests/mimeapps.c index 05816e6..5c99917 100644 --- a/gio/tests/mimeapps.c +++ b/gio/tests/mimeapps.c @@ -349,6 +349,7 @@ test_mime_file (void) str = g_key_file_get_string (keyfile, "Default Applications", contenttype, &error); g_assert_no_error (error); g_assert_cmpstr (str, ==, "myapp.desktop"); + g_free (str); g_key_file_free (keyfile); diff --git a/gio/tests/network-address.c b/gio/tests/network-address.c index 74fbb39..7d6a0da 100644 --- a/gio/tests/network-address.c +++ b/gio/tests/network-address.c @@ -52,6 +52,7 @@ test_parse_uri (void) address = (GNetworkAddress*)g_network_address_parse_uri ("ftp://joe%x-@ftp.gnome.org:2020/start", 8080, &error); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT); g_assert (address == NULL); + g_error_free (error); } typedef struct _ParseTest ParseTest; diff --git a/gio/tests/network-monitor.c b/gio/tests/network-monitor.c index 9ec441a..7205da1 100644 --- a/gio/tests/network-monitor.c +++ b/gio/tests/network-monitor.c @@ -230,6 +230,8 @@ run_tests (GNetworkMonitor *monitor, g_clear_error (&error); } } + + g_main_loop_unref (data.loop); } static void @@ -474,6 +476,16 @@ init_test (TestMask *test) } static void +cleanup_test (TestMask *test) +{ + int i; + + g_object_unref (test->mask); + for (i = 0; test->addresses[i].string; i++) + g_object_unref (test->addresses[i].address); +} + +static void watch_network_changed (GNetworkMonitor *monitor, gboolean available, gpointer user_data) @@ -500,6 +512,8 @@ do_watch_network (void) int main (int argc, char **argv) { + int ret; + g_type_init (); if (argc == 2 && !strcmp (argv[1], "--watch")) @@ -523,5 +537,15 @@ main (int argc, char **argv) g_test_add_func ("/network-monitor/add_networks", test_add_networks); g_test_add_func ("/network-monitor/remove_networks", test_remove_networks); - return g_test_run (); + ret = g_test_run (); + + cleanup_test (&net127); + cleanup_test (&net10); + cleanup_test (&net192); + cleanup_test (&netlocal6); + cleanup_test (&netfe80); + g_object_unref (ip4_default); + g_object_unref (ip6_default); + + return ret; } diff --git a/gio/tests/proxy-test.c b/gio/tests/proxy-test.c index ff65e2a..2842900 100644 --- a/gio/tests/proxy-test.c +++ b/gio/tests/proxy-test.c @@ -475,7 +475,7 @@ proxy_thread (gpointer user_data) gssize nread, nwrote; gchar command[2] = { 0, 0 }; GMainContext *context; - GSource *source; + GSource *read_source, *write_source; context = g_main_context_new (); proxy->loop = g_main_loop_new (context, FALSE); @@ -486,6 +486,7 @@ proxy_thread (gpointer user_data) if (!proxy->client_sock) { g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED); + g_error_free (error); break; } else @@ -516,15 +517,13 @@ proxy_thread (gpointer user_data) g_socket_connect (proxy->server_sock, server.server_addr, NULL, &error); g_assert_no_error (error); - source = g_socket_create_source (proxy->client_sock, G_IO_IN, NULL); - g_source_set_callback (source, (GSourceFunc)proxy_bytes, proxy, NULL); - g_source_attach (source, context); - g_source_unref (source); + read_source = g_socket_create_source (proxy->client_sock, G_IO_IN, NULL); + g_source_set_callback (read_source, (GSourceFunc)proxy_bytes, proxy, NULL); + g_source_attach (read_source, context); - source = g_socket_create_source (proxy->server_sock, G_IO_IN, NULL); - g_source_set_callback (source, (GSourceFunc)proxy_bytes, proxy, NULL); - g_source_attach (source, context); - g_source_unref (source); + write_source = g_socket_create_source (proxy->server_sock, G_IO_IN, NULL); + g_source_set_callback (write_source, (GSourceFunc)proxy_bytes, proxy, NULL); + g_source_attach (write_source, context); g_main_loop_run (proxy->loop); @@ -535,6 +534,11 @@ proxy_thread (gpointer user_data) g_socket_close (proxy->server_sock, &error); g_assert_no_error (error); g_clear_object (&proxy->server_sock); + + g_source_destroy (read_source); + g_source_unref (read_source); + g_source_destroy (write_source); + g_source_unref (write_source); } g_main_loop_unref (proxy->loop); @@ -543,6 +547,10 @@ proxy_thread (gpointer user_data) g_object_unref (proxy->server); g_object_unref (proxy->cancellable); + g_free (proxy->proxy_command); + g_free (proxy->supported_protocol); + g_free (proxy->uri); + return NULL; } @@ -608,6 +616,7 @@ echo_server_thread (gpointer user_data) if (!sock) { g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED); + g_error_free (error); break; } else @@ -633,6 +642,7 @@ echo_server_thread (gpointer user_data) } g_object_unref (data->server); + g_object_unref (data->server_addr); g_object_unref (data->cancellable); return NULL; @@ -826,9 +836,11 @@ assert_direct (GSocketConnection *conn) addr = g_socket_connection_get_remote_address (conn, &error); g_assert_no_error (error); g_assert (!G_IS_PROXY_ADDRESS (addr)); + g_object_unref (addr); addr = g_socket_connection_get_local_address (conn, &error); g_assert_no_error (error); + g_object_unref (addr); g_assert (g_socket_connection_is_connected (conn)); } @@ -895,6 +907,8 @@ assert_single (GSocketConnection *conn) g_assert_cmpstr (proxy_uri, ==, proxy_a.uri); proxy_port = g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr)); g_assert_cmpint (proxy_port, ==, proxy_a.port); + + g_object_unref (addr); } static void @@ -959,6 +973,8 @@ assert_multiple (GSocketConnection *conn) g_assert_cmpstr (proxy_uri, ==, proxy_b.uri); proxy_port = g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr)); g_assert_cmpint (proxy_port, ==, proxy_b.port); + + g_object_unref (addr); } static void @@ -1141,6 +1157,8 @@ main (int argc, g_thread_join (proxy_b.thread); g_thread_join (server.server_thread); + g_object_unref (cancellable); + return result; } diff --git a/gio/tests/unix-streams.c b/gio/tests/unix-streams.c index fd84c50..5985078 100644 --- a/gio/tests/unix-streams.c +++ b/gio/tests/unix-streams.c @@ -65,6 +65,7 @@ writer_thread (gpointer user_data) if (g_cancellable_is_cancelled (writer_cancel)) { + g_clear_error (&err); g_cancellable_cancel (main_cancel); g_object_unref (out); return NULL; -- 2.7.4