[empathy/gnome-3-4] empathy-chat: abort chat_log_filter if object was destroyed



commit 24b7469a75d9f1c3dd6ac596d7e8394c64e8dff8
Author: Debarshi Ray <debarshir src gnome org>
Date:   Fri Jun 8 16:41:08 2012 +0200

    empathy-chat: abort chat_log_filter if object was destroyed
    
    Fixes: https://bugzilla.gnome.org/677641

 libempathy-gtk/empathy-chat.c |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)
---
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index d5e72cb..211b084 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -2520,26 +2520,35 @@ static gboolean
 chat_log_filter (TplEvent *event,
 		 gpointer user_data)
 {
-	EmpathyChat *chat = user_data;
+	TpWeakRef *wr = user_data;
+	EmpathyChat *chat = tp_weak_ref_dup_object (wr);
 	EmpathyMessage *message;
-	EmpathyChatPriv *priv = GET_PRIV (chat);
+	EmpathyChatPriv *priv;
 	const GList *pending;
+	bool retval = FALSE;
+
+	if (chat == NULL)
+		return FALSE;
 
 	g_return_val_if_fail (TPL_IS_EVENT (event), FALSE);
 	g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
 
+	priv = GET_PRIV (chat);
+
 	pending = empathy_tp_chat_get_pending_messages (priv->tp_chat);
 	message = empathy_message_from_tpl_log_event (event);
 
 	for (; pending; pending = g_list_next (pending)) {
-		if (empathy_message_equal (message, pending->data)) {
-			g_object_unref (message);
-			return FALSE;
-		}
+		if (empathy_message_equal (message, pending->data))
+			goto out;
 	}
 
+	retval = TRUE;
+
+out:
 	g_object_unref (message);
-	return TRUE;
+	g_object_unref (chat);
+	return retval;
 }
 
 
@@ -2655,6 +2664,7 @@ chat_add_logs (EmpathyChat *chat)
 {
 	EmpathyChatPriv *priv = GET_PRIV (chat);
 	TplEntity       *target;
+	TpWeakRef       *wr;
 
 	if (!priv->id) {
 		return;
@@ -2670,15 +2680,16 @@ chat_add_logs (EmpathyChat *chat)
 	  target = tpl_entity_new (priv->id, TPL_ENTITY_CONTACT, NULL, NULL);
 
 	priv->retrieving_backlogs = TRUE;
+	wr = tp_weak_ref_new (chat, NULL, NULL);
 	tpl_log_manager_get_filtered_events_async (priv->log_manager,
 						   priv->account,
 						   target,
 						   TPL_EVENT_MASK_TEXT,
 						   5,
 						   chat_log_filter,
-						   chat,
+						   wr,
 						   got_filtered_messages_cb,
-						   tp_weak_ref_new (chat, NULL, NULL));
+						   wr);
 
 	g_object_unref (target);
 }



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