changeset 24903:115a2e9ea8b3

2008.12.28 - flos <lonicerae(at)gmail.com> * Fixes #7908, fixed a bug which would crash OpenQ while login in qq_network.c 2008.12.28 - flos <lonicerae(at)gmail.com> * References #7908
author SHiNE CsyFeK <csyfek@gmail.com>
date Sun, 04 Jan 2009 15:11:08 +0000
parents fc07bafe9e9b
children 88b963749fea
files libpurple/protocols/qq/ChangeLog libpurple/protocols/qq/qq_network.c
diffstat 2 files changed, 30 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/qq/ChangeLog	Sun Jan 04 11:30:12 2009 +0000
+++ b/libpurple/protocols/qq/ChangeLog	Sun Jan 04 15:11:08 2009 +0000
@@ -1,3 +1,9 @@
+2008.12.28 - flos <lonicerae(at)gmail.com>
+	* Fixes #7908
+
+2008.12.28 - flos <lonicerae(at)gmail.com>
+	* References #7908
+
 2008.12.25 - flos <lonicerae(at)gmail.com>
 	* References #7821
 	* Updated authors
--- a/libpurple/protocols/qq/qq_network.c	Sun Jan 04 11:30:12 2009 +0000
+++ b/libpurple/protocols/qq/qq_network.c	Sun Jan 04 15:11:08 2009 +0000
@@ -174,14 +174,16 @@
  *  Please conside tcp_pending and udp_pending */
 gboolean qq_connect_later(gpointer data)
 {
-	PurpleConnection *gc = (PurpleConnection *) data;
-	qq_data *qd;
-	char *server;
+	PurpleConnection *gc;
+	char *tmp_server;
 	int port;
 	gchar **segments;
+	qq_data *qd;
 
+	gc = (PurpleConnection *) data;
 	g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, FALSE);
 	qd = (qq_data *) gc->proto_data;
+	tmp_server = NULL;
 
 	if (qd->check_watcher > 0) {
 		purple_timeout_remove(qd->check_watcher);
@@ -191,9 +193,11 @@
 
 	if (qd->redirect_ip.s_addr != 0) {
 		/* redirect to new server */
-		server = g_strdup_printf("%s:%d", inet_ntoa(qd->redirect_ip), qd->redirect_port);
-		qd->servers = g_list_append(qd->servers, server);
-		qd->curr_server = server;
+		tmp_server = g_strdup_printf("%s:%d", inet_ntoa(qd->redirect_ip), qd->redirect_port);
+		qd->servers = g_list_append(qd->servers, tmp_server);
+
+		qd->curr_server = tmp_server;
+		tmp_server = NULL;
 
 		qd->redirect_ip.s_addr = 0;
 		qd->redirect_port = 0;
@@ -211,21 +215,30 @@
 	}
 
 	segments = g_strsplit_set(qd->curr_server, ":", 0);
-	server = g_strdup(segments[0]);
-	port = atoi(segments[1]);
-	if (port <= 0) {
-		purple_debug_info("QQ", "Port not define in %s\n", qd->curr_server);
+	tmp_server = g_strdup(segments[0]);
+	if (NULL != segments[1]) {
+		port = atoi(segments[1]);
+		if (port <= 0) {
+			purple_debug_info("QQ", "Port not define in %s, use default.\n", qd->curr_server);
+			port = QQ_DEFAULT_PORT;
+		}
+	} else {
+		purple_debug_info("QQ", "Error splitting server string: %s, setting port to default.\n", qd->curr_server);
 		port = QQ_DEFAULT_PORT;
 	}
+
 	g_strfreev(segments);
 
 	qd->connect_retry--;
-	if ( !connect_to_server(gc, server, port) ) {
+	if ( !connect_to_server(gc, tmp_server, port) ) {
 			purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
 				_("Unable to connect."));
 	}
 
+	g_free(tmp_server);
+	tmp_server = NULL;
+
 	qd->check_watcher = purple_timeout_add_seconds(QQ_CONNECT_CHECK, connect_check, gc);
 	return FALSE;	/* timeout callback stops */
 }