[empathy] accounts-dialog: avoid leaking the account status message



commit 55b79bd79477ddb3be777d760e19fa1bc468e56b
Author: Rob Bradford <rob linux intel com>
Date:   Thu Jun 3 14:24:21 2010 +0100

    accounts-dialog: avoid leaking the account status message
    
    Originally this function mixed const and allocated strings using the same
    variable, resulting in leaks. This change refactors the code slightly to
    prevent such leaks.
    
    Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=620476

 src/empathy-accounts-dialog.c |   53 +++++++++++++++++++++++++++++++---------
 1 files changed, 41 insertions(+), 12 deletions(-)
---
diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c
index 2acac45..d81d3de 100644
--- a/src/empathy-accounts-dialog.c
+++ b/src/empathy-accounts-dialog.c
@@ -191,12 +191,22 @@ accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
 }
 
 static void
+accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
+    const gchar *message)
+{
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+  gchar *message_markup;
+
+  message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
+  gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
+  g_free (message_markup);
+}
+
+static void
 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
     TpAccount *account)
 {
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
-  const gchar               *message;
-  gchar                     *message_markup;
   gchar                     *status_message = NULL;
   guint                     status;
   guint                     reason;
@@ -259,7 +269,8 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
       switch (status)
         {
           case TP_CONNECTION_STATUS_CONNECTING:
-            message = _("Connectingâ?¦");
+            accounts_dialog_status_infobar_set_message (dialog,
+                _("Connectingâ?¦"));
             gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
                 GTK_MESSAGE_INFO);
 
@@ -270,14 +281,24 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
           case TP_CONNECTION_STATUS_CONNECTED:
             if (g_strcmp0 (status_message, "") == 0)
               {
+                gchar *message;
+
                 message = g_strdup_printf ("%s",
                     empathy_presence_get_default_message (presence));
+
+                accounts_dialog_status_infobar_set_message (dialog, message);
+                g_free (message);
               }
             else
               {
+                gchar *message;
+
                 message = g_strdup_printf ("%s â?? %s",
                     empathy_presence_get_default_message (presence),
                     status_message);
+
+                accounts_dialog_status_infobar_set_message (dialog, message);
+                g_free (message);
               }
             gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
                 GTK_MESSAGE_INFO);
@@ -286,31 +307,41 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
             gtk_widget_hide (priv->throbber);
             break;
           case TP_CONNECTION_STATUS_DISCONNECTED:
-            message = g_strdup_printf (_("Disconnected â?? %s"),
-                empathy_status_reason_get_default_message (reason));
-
             if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
               {
+                gchar *message;
+
                 message = g_strdup_printf (_("Offline â?? %s"),
                     empathy_status_reason_get_default_message (reason));
                 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
                     GTK_MESSAGE_WARNING);
+
+                accounts_dialog_status_infobar_set_message (dialog, message);
+                g_free (message);
               }
             else
               {
+                gchar *message;
+
+                message = g_strdup_printf (_("Disconnected â?? %s"),
+                    empathy_status_reason_get_default_message (reason));
                 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
                     GTK_MESSAGE_ERROR);
+
+                accounts_dialog_status_infobar_set_message (dialog, message);
+                g_free (message);
               }
 
             if (!empathy_connectivity_is_online (priv->connectivity))
-               message = _("Offline â?? No Network Connection");
+               accounts_dialog_status_infobar_set_message (dialog,
+                    _("Offline â?? No Network Connection"));
 
             gtk_spinner_stop (GTK_SPINNER (priv->throbber));
             gtk_widget_show (priv->image_status);
             gtk_widget_hide (priv->throbber);
             break;
           default:
-            message = _("Unknown Status");
+            accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
             gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
                 GTK_MESSAGE_WARNING);
 
@@ -321,7 +352,8 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
     }
   else
     {
-      message = _("Offline â?? Account Disabled");
+      accounts_dialog_status_infobar_set_message (dialog,
+          _("Offline â?? Account Disabled"));
 
       gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
           GTK_MESSAGE_WARNING);
@@ -330,8 +362,6 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
       gtk_widget_hide (priv->throbber);
     }
 
-  message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
-  gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
   gtk_widget_show (priv->label_status);
 
   if (!creating_account)
@@ -340,7 +370,6 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
     gtk_widget_hide (priv->infobar);
 
   g_free (status_message);
-  g_free (message_markup);
 }
 
 void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]