[glib] Fix leaks in GSocketClient and GThreadedResolver
- From: Dan Winship <danw src gnome org>
- To: svn-commits-list gnome org
- Subject: [glib] Fix leaks in GSocketClient and GThreadedResolver
- Date: Thu, 23 Jul 2009 20:29:00 +0000 (UTC)
commit 45067ab9e97de0992acd4004d6e4de957d6c28f4
Author: Dan Winship <danw gnome org>
Date: Thu Jul 23 16:27:01 2009 -0400
Fix leaks in GSocketClient and GThreadedResolver
Also update gio/tests/send-data.c to test async connection, and free
more stuff in several tests to make leaks easier to see.
gio/gsocketclient.c | 3 +++
gio/gthreadedresolver.c | 6 +++++-
gio/tests/send-data.c | 25 +++++++++++++++++++++----
gio/tests/socket-client.c | 2 ++
gio/tests/socket-server.c | 1 +
5 files changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/gio/gsocketclient.c b/gio/gsocketclient.c
index 72c9429..7908aec 100644
--- a/gio/gsocketclient.c
+++ b/gio/gsocketclient.c
@@ -676,6 +676,7 @@ g_socket_client_async_connect_complete (GSocketClientAsyncConnectData *data)
g_socket_set_blocking (data->current_socket, TRUE);
connection = g_socket_connection_factory_create_connection (data->current_socket);
+ g_object_unref (data->current_socket);
g_simple_async_result_set_op_res_gpointer (data->result,
connection,
g_object_unref);
@@ -683,6 +684,8 @@ g_socket_client_async_connect_complete (GSocketClientAsyncConnectData *data)
g_simple_async_result_complete (data->result);
g_object_unref (data->result);
+ g_object_unref (data->enumerator);
+ g_slice_free (GSocketClientAsyncConnectData, data);
}
diff --git a/gio/gthreadedresolver.c b/gio/gthreadedresolver.c
index c259b57..bd7a829 100644
--- a/gio/gthreadedresolver.c
+++ b/gio/gthreadedresolver.c
@@ -320,6 +320,9 @@ resolve_sync (GThreadedResolver *gtr,
{
req->resolve_func (req, error);
g_mutex_unlock (req->mutex);
+
+ g_threaded_resolver_request_complete (req, FALSE);
+ g_threaded_resolver_request_unref (req);
return;
}
@@ -344,7 +347,8 @@ resolve_async (GThreadedResolver *gtr,
{
req->async_result = g_simple_async_result_new (G_OBJECT (gtr),
callback, user_data, tag);
- g_simple_async_result_set_op_res_gpointer (req->async_result, req, NULL);
+ g_simple_async_result_set_op_res_gpointer (req->async_result, req,
+ (GDestroyNotify)g_threaded_resolver_request_unref);
g_thread_pool_push (gtr->thread_pool, req, NULL);
g_mutex_unlock (req->mutex);
}
diff --git a/gio/tests/send-data.c b/gio/tests/send-data.c
index d2a702b..a2592ce 100644
--- a/gio/tests/send-data.c
+++ b/gio/tests/send-data.c
@@ -97,15 +97,29 @@ main (int argc, char *argv[])
}
client = g_socket_client_new ();
- connection = g_socket_client_connect_to_host (client,
- argv[1],
- 7777,
- cancellable, &error);
+
+ if (async)
+ {
+ GAsyncResult *res;
+ g_socket_client_connect_to_host_async (client, argv[1], 7777,
+ cancellable, async_cb, &res);
+ g_main_loop_run (loop);
+ connection = g_socket_client_connect_to_host_finish (client, res, &error);
+ g_object_unref (res);
+ }
+ else
+ {
+ connection = g_socket_client_connect_to_host (client,
+ argv[1],
+ 7777,
+ cancellable, &error);
+ }
if (connection == NULL)
{
g_printerr ("%s can't connect: %s\n", argv[0], error->message);
return 1;
}
+ g_object_unref (client);
address = g_socket_connection_get_remote_address (connection, &error);
if (!address)
@@ -125,6 +139,7 @@ main (int argc, char *argv[])
while (fgets(buffer, sizeof (buffer), stdin) != NULL)
{
+ /* FIXME if (async) */
if (!g_output_stream_write_all (out, buffer, strlen (buffer),
NULL, cancellable, &error))
{
@@ -159,5 +174,7 @@ main (int argc, char *argv[])
}
}
+ g_object_unref (connection);
+
return 0;
}
diff --git a/gio/tests/socket-client.c b/gio/tests/socket-client.c
index 8409a5f..f0f7c4e 100644
--- a/gio/tests/socket-client.c
+++ b/gio/tests/socket-client.c
@@ -181,6 +181,7 @@ main (int argc,
g_object_unref (address);
}
g_object_unref (enumerator);
+ g_object_unref (connectable);
g_print ("Connected to %s\n",
socket_address_to_string (address));
@@ -293,6 +294,7 @@ main (int argc,
}
g_object_unref (G_OBJECT (socket));
+ g_object_unref (G_OBJECT (address));
return 0;
}
diff --git a/gio/tests/socket-server.c b/gio/tests/socket-server.c
index b98c696..205cdaf 100644
--- a/gio/tests/socket-server.c
+++ b/gio/tests/socket-server.c
@@ -158,6 +158,7 @@ main (int argc,
g_printerr ("Can't bind socket: %s\n", error->message);
return 1;
}
+ g_object_unref (src_address);
if (!use_udp)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]