changeset 17583:9fafe265567f

Fix purple_blist_remove_buddy() so it doesn't crash (NULL pointer dereference) if called on a PurpleBuddy node that hasn't been inserted into the list yet.
author Stu Tomlinson <stu@nosnilmot.com>
date Sun, 10 Jun 2007 19:43:21 +0000
parents 192a86dfade8
children 43da9c881fe9 ba1478c35cc0
files libpurple/blist.c
diffstat 1 files changed, 23 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/blist.c	Sun Jun 10 18:27:11 2007 +0000
+++ b/libpurple/blist.c	Sun Jun 10 19:43:21 2007 +0000
@@ -1774,7 +1774,7 @@
 
 	node = (PurpleBlistNode *)buddy;
 	cnode = node->parent;
-	gnode = cnode->parent;
+	gnode = (cnode != NULL) ? cnode->parent : NULL;
 	contact = (PurpleContact *)cnode;
 	group = (PurpleGroup *)gnode;
 
@@ -1783,35 +1783,37 @@
 		node->prev->next = node->next;
 	if (node->next)
 		node->next->prev = node->prev;
-	if (cnode->child == node)
+	if ((cnode != NULL) && (cnode->child == node))
 		cnode->child = node->next;
 
 	/* Adjust size counts */
-	if (PURPLE_BUDDY_IS_ONLINE(buddy)) {
-		contact->online--;
-		if (contact->online == 0)
-			group->online--;
+	if (contact != NULL) {
+		if (PURPLE_BUDDY_IS_ONLINE(buddy)) {
+			contact->online--;
+			if (contact->online == 0)
+				group->online--;
+		}
+		if (purple_account_is_connected(buddy->account)) {
+			contact->currentsize--;
+			if (contact->currentsize == 0)
+				group->currentsize--;
+		}
+		contact->totalsize--;
+
+		/* Re-sort the contact */
+		if (cnode->child && contact->priority == buddy) {
+			purple_contact_invalidate_priority_buddy(contact);
+			if (ops && ops->update)
+				ops->update(purplebuddylist, cnode);
+		}
 	}
-	if (purple_account_is_connected(buddy->account)) {
-		contact->currentsize--;
-		if (contact->currentsize == 0)
-			group->currentsize--;
-	}
-	contact->totalsize--;
 
 	purple_blist_schedule_save();
 
-	/* Re-sort the contact */
-	if (cnode->child && contact->priority == buddy) {
-		purple_contact_invalidate_priority_buddy(contact);
-		if (ops && ops->update)
-			ops->update(purplebuddylist, cnode);
-	}
-
 	/* Remove this buddy from the buddies hash table */
 	hb.name = g_strdup(purple_normalize(buddy->account, buddy->name));
 	hb.account = buddy->account;
-	hb.group = ((PurpleBlistNode*)buddy)->parent->parent;
+	hb.group = gnode;
 	g_hash_table_remove(purplebuddylist->buddies, &hb);
 	g_free(hb.name);
 
@@ -1841,7 +1843,7 @@
 	while (g_source_remove_by_user_data((gpointer *)buddy));
 
 	/* If the contact is empty then remove it */
-	if (!cnode->child)
+	if ((contact != NULL) && !cnode->child)
 		purple_blist_remove_contact(contact);
 }