From 4ae42ceb3c6f671d41a390aa664edd2f5f21fb4a Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 17 Nov 2011 13:01:05 -0500 Subject: [PATCH] Clear proxy address upon retry The proxy address was not cleared between each attempt. That would lead to leak or worse, trying to do the proxy handshake on the final destination address. To make all this safer, I have regroup all the cleanup where the iterations starts. https://bugzilla.gnome.org/show_bug.cgi?id=664141 --- gio/gsocketclient.c | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/gio/gsocketclient.c b/gio/gsocketclient.c index 4ef6dd3..e65404f 100644 --- a/gio/gsocketclient.c +++ b/gio/gsocketclient.c @@ -1172,6 +1172,12 @@ set_last_error (GSocketClientAsyncConnectData *data, static void enumerator_next_async (GSocketClientAsyncConnectData *data) { + /* We need to cleanup the state */ + g_clear_object (&data->current_socket); + g_clear_object (&data->current_addr); + g_clear_object (&data->proxy_addr); + g_clear_object (&data->connection); + g_socket_address_enumerator_next_async (data->enumerator, data->cancellable, g_socket_client_enumerator_callback, @@ -1197,11 +1203,6 @@ g_socket_client_tls_handshake_callback (GObject *object, else { g_object_unref (object); - g_object_unref (data->current_socket); - data->current_socket = NULL; - g_object_unref (data->connection); - data->connection = NULL; - enumerator_next_async (data); } } @@ -1232,11 +1233,6 @@ g_socket_client_tls_handshake (GSocketClientAsyncConnectData *data) } else { - g_object_unref (data->current_socket); - data->current_socket = NULL; - g_object_unref (data->connection); - data->connection = NULL; - enumerator_next_async (data); } } @@ -1254,9 +1250,6 @@ g_socket_client_proxy_connect_callback (GObject *object, &data->last_error); if (!data->connection) { - g_object_unref (data->current_socket); - data->current_socket = NULL; - enumerator_next_async (data); return; } @@ -1291,11 +1284,6 @@ g_socket_client_proxy_connect (GSocketClientAsyncConnectData *data) G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("Trying to proxy over non-TCP connection is not supported.")); - g_object_unref (data->connection); - data->connection = NULL; - g_object_unref (data->current_socket); - data->current_socket = NULL; - enumerator_next_async (data); } else if (proxy) @@ -1317,13 +1305,6 @@ g_socket_client_proxy_connect (GSocketClientAsyncConnectData *data) _("Proxy protocol '%s' is not supported."), protocol); - g_object_unref (data->current_socket); - data->current_socket = NULL; - g_object_unref (data->connection); - data->connection = NULL; - g_object_unref (data->current_socket); - data->current_socket = NULL; - enumerator_next_async (data); } } @@ -1350,8 +1331,6 @@ g_socket_client_socket_callback (GSocket *socket, { /* Cancelled, return done with last error being cancelled */ g_clear_error (&data->last_error); - g_clear_object (&data->current_socket); - g_clear_object (&data->current_addr); g_cancellable_set_error_if_cancelled (data->cancellable, &data->last_error); @@ -1365,10 +1344,7 @@ g_socket_client_socket_callback (GSocket *socket, { clarify_connect_error (error, data->connectable, data->current_addr); - set_last_error (data, error); - g_clear_object (&data->current_socket); - g_clear_object (&data->current_addr); /* try next one */ enumerator_next_async (data); -- 2.7.4