im.pidgin.cpw.resiak.disconnectreason: afe36a0846b5b2528872b81e6af1706a9ed378ee

resiak at soc.pidgin.im resiak at soc.pidgin.im
Sat Nov 3 07:13:16 EDT 2007


-----------------------------------------------------------------
Revision: afe36a0846b5b2528872b81e6af1706a9ed378ee
Ancestor: 8e0477db533961b6d2ede63c5b8ac618ec428dd0
Author: resiak at soc.pidgin.im
Date: 2007-11-02T19:36:34
Branch: im.pidgin.cpw.resiak.disconnectreason

Modified files:
        libpurple/account.c

ChangeLog: 

Extract setting an account's current error to a static function.  In the
process, g_strdup the description passed to connection_error_cb since it's not
guaranteed (and isn't, at least on MSN) to be a valid pointer for ever.

-------------- next part --------------
============================================================
--- libpurple/account.c	4b2ebcdbf96ff2e6b5ff1e7cb45720c47f135a6b
+++ libpurple/account.c	2293762939a2fdde5be8e59379b68bc8f3d2c2d4
@@ -2239,25 +2239,42 @@ static void
 }
 
 static void
-connection_error_cb(PurpleConnection *gc,
-                    PurpleConnectionError err,
-                    const gchar *desc,
-                    gpointer unused)
+set_current_error(PurpleAccount *account,
+                  PurpleConnectionErrorInfo *new_err)
 {
-	PurpleAccount *account = purple_connection_get_account(gc);
 	PurpleAccountPrivate *priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
-	PurpleConnectionErrorInfo *old = priv->current_error;
+	PurpleConnectionErrorInfo *old_err = priv->current_error;
 
-	priv->current_error = g_new0(PurpleConnectionErrorInfo, 1);
-	priv->current_error->type = err;
-	priv->current_error->description = desc;
+	if(new_err == old_err)
+		return;
 
+	priv->current_error = new_err;
+
 	purple_signal_emit(purple_accounts_get_handle(),
 	                   "account-error-changed",
-	                   account, old, priv->current_error);
-	g_free(old);
+	                   account, old_err, new_err);
+
+	if(old_err)
+		g_free(old_err->description);
+
+	g_free(old_err);
 }
 
+static void
+connection_error_cb(PurpleConnection *gc,
+                    PurpleConnectionError type,
+                    const gchar *description,
+                    gpointer unused)
+{
+	PurpleAccount *account = purple_connection_get_account(gc);
+	PurpleConnectionErrorInfo *err = g_new0(PurpleConnectionErrorInfo, 1);
+
+	err->type = type;
+	err->description = g_strdup(description);
+
+	set_current_error(account, err);
+}
+
 const PurpleConnectionErrorInfo *
 purple_account_get_current_error(PurpleAccount *account)
 {
@@ -2268,18 +2285,7 @@ purple_account_clear_current_error(Purpl
 static void
 purple_account_clear_current_error(PurpleAccount *account)
 {
-	PurpleAccountPrivate *priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
-	PurpleConnectionErrorInfo *old;
-
-	if (priv->current_error)
-	{
-		old = priv->current_error;
-		priv->current_error = NULL;
-		purple_signal_emit(purple_accounts_get_handle(),
-		                   "account-error-changed",
-		                   account, old, priv->current_error);
-		g_free (old);
-	}
+	set_current_error(account, NULL);
 }
 
 


More information about the Commits mailing list