pidgin/plugins/cap/cap.c

changeset 18938
39f90d00cd5e
parent 17364
82d48f3b2967
child 19859
71d37b57eff2
--- 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. */

mercurial