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.
This commit is contained in:
Dan Winship 2009-07-23 16:27:01 -04:00
parent 66ff2542d3
commit 45067ab9e9
5 changed files with 32 additions and 5 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)
{