# HG changeset patch # User Evan Schoenberg # Date 1178214636 0 # Node ID 52c776782b95a947ad090d6f2d4fa2ba26f4c24f # Parent 844ed04187441206587030901f0e318f9f0488ed Protect icon with ref/unref guards since it may be freed over the course of the while() loop. I thought this would fix #398, but something else is wrong, too. diff -r 844ed0418744 -r 52c776782b95 libpurple/buddyicon.c --- a/libpurple/buddyicon.c Thu May 03 17:43:07 2007 +0000 +++ b/libpurple/buddyicon.c Thu May 03 17:50:36 2007 +0000 @@ -379,13 +379,16 @@ account = purple_buddy_icon_get_account(icon); username = purple_buddy_icon_get_username(icon); - /* If no data exists, then call the functions below with NULL to - * unset the icon. They will then unref the icon and it should be - * destroyed. The only way it wouldn't be destroyed is if someone + /* If no data exists (icon->img == NULL), then call the functions below + * with NULL to unset the icon. They will then unref the icon and it should + * be destroyed. The only way it wouldn't be destroyed is if someone * else is holding a reference to it, in which case they can kill * the icon when they realize it has no data. */ icon_to_set = icon->img ? icon : NULL; + /* Ensure that icon remains valid throughout */ + if (icon) purple_buddy_icon_ref(icon); + buddies = purple_find_buddies(account, username); while (buddies != NULL) { @@ -393,7 +396,6 @@ char *old_icon; purple_buddy_set_icon(buddy, icon_to_set); - old_icon = g_strdup(purple_blist_node_get_string((PurpleBlistNode *)buddy, "buddy_icon")); if (icon->img && purple_buddy_icons_is_caching()) @@ -431,6 +433,9 @@ if (conv != NULL) purple_conv_im_set_icon(PURPLE_CONV_IM(conv), icon_to_set); + + /* icon's refcount was incremented above */ + if (icon) purple_buddy_icon_unref(icon); } void