changeset 14403:646dcf11b4eb

[gaim-migrate @ 17111] Fix two crashes that evands noticed in the Adium crash reporter. Basically what was happening is that our url fetching code saw a redirect, and then it did a second request for the redirected page. But whoever called gaim_util_fetch_url() in the first place still had a reference to the (now freed) url fetch data. The solution is to reuse the url fetch data structure for the redirect request. The Adium crash reporter is ill, yo. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 01 Sep 2006 10:05:30 +0000
parents 648e33275d9d
children 8ff8f1c897b5
files libgaim/util.c
diffstat 1 files changed, 29 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/libgaim/util.c	Fri Sep 01 08:52:23 2006 +0000
+++ b/libgaim/util.c	Fri Sep 01 10:05:30 2006 +0000
@@ -3078,7 +3078,8 @@
 	gaim_util_fetch_url_cancel(gfud);
 }
 
-/* TODO: This totally destroys cancelability. */
+static void url_fetch_connect_cb(gpointer url_data, gint source, const gchar *error_message);
+
 static gboolean
 parse_redirect(const char *data, size_t data_len, gint sock,
 			   GaimUtilFetchUrlData *gfud)
@@ -3123,14 +3124,33 @@
 
 		gaim_debug_info("util", "Redirecting to %s\n", new_url);
 
-		/* Try again, with this new location. */
-		gaim_util_fetch_url_request(new_url, full, gfud->user_agent,
-				gfud->http11, NULL, gfud->include_headers,
-				gfud->callback, gfud->user_data);
-
-		/* Free the old connection */
-		g_free(new_url);
-		gaim_util_fetch_url_cancel(gfud);
+		/*
+		 * Try again, with this new location.  This code is somewhat
+		 * ugly, but we need to reuse the gfud because whoever called
+		 * us is holding a reference to it.
+		 */
+		g_free(gfud->url);
+		gfud->url = new_url;
+		gfud->full = full;
+		g_free(gfud->request);
+		gfud->request = NULL;
+
+		g_free(gfud->website.user);
+		g_free(gfud->website.passwd);
+		g_free(gfud->website.address);
+		g_free(gfud->website.page);
+		gaim_url_parse(new_url, &gfud->website.address, &gfud->website.port,
+					   &gfud->website.page, &gfud->website.user, &gfud->website.passwd);
+
+		gfud->connect_data = gaim_proxy_connect(NULL,
+				gfud->website.address, gfud->website.port,
+				url_fetch_connect_cb, gfud);
+
+		if (gfud->connect_data == NULL)
+		{
+			gaim_util_fetch_url_error(gfud, _("Unable to connect to %s"),
+					gfud->website.address);
+		}
 
 		return TRUE;
 	}