# HG changeset patch # User Daniel Atallah # Date 1185332013 0 # Node ID 04745409561826f250ea38ff2252449a73c08610 # Parent 41fc033b63af76553eb75f6dea76f0073f0a1368 Prevent an invalid PurpleBuddy pointer from being used by cap when a non-saved (e.g. Bonjour) buddy logs off and back on. It looks like the code used to (or was intended to) handle this scenario better. Fixes #1860. diff -r 41fc033b63af -r 047454095618 pidgin/plugins/cap/cap.c --- a/pidgin/plugins/cap/cap.c Wed Jul 25 00:20:27 2007 +0000 +++ b/pidgin/plugins/cap/cap.c Wed Jul 25 02:53:33 2007 +0000 @@ -107,25 +107,26 @@ } static CapStatistics * get_stats_for(PurpleBuddy *buddy) { - gchar *buddy_name; CapStatistics *stats; g_return_val_if_fail(buddy != NULL, NULL); - buddy_name = g_strdup(buddy->name); - stats = g_hash_table_lookup(_buddy_stats, buddy_name); + stats = g_hash_table_lookup(_buddy_stats, buddy->name); if(!stats) { stats = g_malloc(sizeof(CapStatistics)); stats->last_message = -1; stats->last_message_status_id = NULL; stats->last_status_id = NULL; stats->prediction = NULL; - g_hash_table_insert(_buddy_stats, buddy_name, stats); stats->buddy = buddy; stats->last_seen = -1; stats->last_status_id = ""; + + g_hash_table_insert(_buddy_stats, g_strdup(buddy->name), stats); } else { - g_free(buddy_name); + /* This may actually be a different PurpleBuddy than what is in stats. + * We replace stats->buddy to make sure we're looking at a valid pointer. */ + stats->buddy = buddy; } generate_prediction(stats); return stats; @@ -409,7 +410,7 @@ /* buddy-signed-on */ static void buddy_signed_on(PurpleBuddy *buddy) { CapStatistics *stats = get_stats_for(buddy); - + /* If the statistic object existed but doesn't have a buddy pointer associated * with it then reassociate one with it. The pointer being null is a result * of a buddy with existing stats signing off and Purple sticking around. */