From 55b79bd79477ddb3be777d760e19fa1bc468e56b Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 3 Jun 2010 14:24:21 +0100 Subject: 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 file changed, 41 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 2acac45a5..d81d3de2d 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -190,13 +190,23 @@ accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog, g_free (text); } +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 ("%s", 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 ("%s", 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 -- cgit v1.2.3