Set the session error after disconnecting the servconn instead of before.

Tue, 21 Jul 2009 03:56:44 +0000

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Tue, 21 Jul 2009 03:56:44 +0000
changeset 27903
602a8a17b76a
parent 27902
74e7df7a19f3
child 27904
c1e552435b02

Set the session error after disconnecting the servconn instead of before.
The disconnect callback may try to do something that would set another
error, thus hiding the original one.

libpurple/protocols/msn/servconn.c file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/msn/servconn.c	Mon Jul 20 05:11:50 2009 +0000
+++ b/libpurple/protocols/msn/servconn.c	Tue Jul 21 03:56:44 2009 +0000
@@ -125,13 +125,14 @@
 void
 msn_servconn_got_error(MsnServConn *servconn, MsnServConnError error)
 {
-	char *tmp;
+	MsnSession *session = servconn->session;
+	MsnServConnType type = servconn->type;
 	const char *reason;
 
 	const char *names[] = { "Notification", "Switchboard" };
 	const char *name;
 
-	name = names[servconn->type];
+	name = names[type];
 
 	switch (error)
 	{
@@ -147,14 +148,8 @@
 
 	purple_debug_error("msn", "Connection error from %s server (%s): %s\n",
 					 name, servconn->host, reason);
-	tmp = g_strdup_printf(_("Connection error from %s server:\n%s"),
-						  name, reason);
 
-	if (servconn->type == MSN_SERVCONN_NS)
-	{
-		msn_session_set_error(servconn->session, MSN_ERROR_SERVCONN, tmp);
-	}
-	else if (servconn->type == MSN_SERVCONN_SB)
+	if (type == MSN_SERVCONN_SB)
 	{
 		MsnSwitchBoard *swboard;
 		swboard = servconn->cmdproc->data;
@@ -162,9 +157,16 @@
 			swboard->error = MSN_SB_ERROR_CONNECTION;
 	}
 
+	/* servconn->disconnect_cb may destroy servconn, so don't use it again */
 	msn_servconn_disconnect(servconn);
 
-	g_free(tmp);
+	if (type == MSN_SERVCONN_NS)
+	{
+		char *tmp = g_strdup_printf(_("Connection error from %s server:\n%s"),
+		                            name, reason);
+		msn_session_set_error(session, MSN_ERROR_SERVCONN, tmp);
+		g_free(tmp);
+	}
 }
 
 /**************************************************************************

mercurial