diff libpurple/buddyicon.c @ 16391:24bbd7e46bfe

Change the imgstore and by extension, then the buddy icon code to take over the references to icon data instead of calling g_memdup(). This eliminates g_memdup()ing and g_free()ing in ~50% of the callers. For the rest, it's no worse (they now do a g_memdup() instead of the core) and they may be able to be modified in the future to avoid that.
author Richard Laager <rlaager@wiktel.com>
date Wed, 25 Apr 2007 22:23:29 +0000
parents 4fc51a87ce42
children 3be560001d26
line wrap: on
line diff
--- a/libpurple/buddyicon.c	Wed Apr 25 21:48:56 2007 +0000
+++ b/libpurple/buddyicon.c	Wed Apr 25 22:23:29 2007 +0000
@@ -236,7 +236,10 @@
 	{
 		file = purple_buddy_icon_data_calculate_filename(icon_data, icon_len);
 		if (file == NULL)
+		{
+			g_free(icon_data);
 			return NULL;
+		}
 	}
 	else
 		file = g_strdup(filename);
@@ -244,6 +247,7 @@
 	if ((img = g_hash_table_lookup(icon_data_cache, file)))
 	{
 		g_free(file);
+		g_free(icon_data);
 		return purple_imgstore_ref(img);
 	}
 
@@ -438,8 +442,11 @@
 	old_img = icon->img;
 	icon->img = NULL;
 
-	if (data != NULL && len > 0)
-		icon->img = purple_buddy_icon_data_new(data, len, NULL);
+	if (data != NULL)
+		if (len > 0)
+			icon->img = purple_buddy_icon_data_new(data, len, NULL);
+		else
+			g_free(data);
 
 	icon->checksum = g_strdup(checksum);
 
@@ -610,7 +617,6 @@
 				icon->img = NULL;
 				checksum = g_strdup(purple_blist_node_get_string((PurpleBlistNode*)b, "icon_checksum"));
 				purple_buddy_icon_set_data(icon, data, len, checksum);
-				g_free(data);
 			}
 			g_free(path);
 		}
@@ -658,7 +664,6 @@
 	{
 		g_free(path);
 		img = purple_buddy_icon_data_new(data, len, account_icon_file);
-		g_free(data);
 		g_hash_table_insert(pointer_icon_cache, account, img);
 		return img;
 	}
@@ -680,7 +685,6 @@
 	if (icon_data != NULL && icon_len > 0)
 	{
 		img = purple_buddy_icon_data_new(icon_data, icon_len, NULL);
-		g_free(icon_data);
 	}
 
 	old_icon = g_strdup(purple_account_get_string(account, "buddy_icon", NULL));
@@ -757,7 +761,6 @@
 	{
 		g_free(path);
 		img = purple_buddy_icon_data_new(data, len, custom_icon_file);
-		g_free(data);
 		g_hash_table_insert(pointer_icon_cache, contact, img);
 		return img;
 	}
@@ -780,7 +783,6 @@
 	if (icon_data != NULL && icon_len > 0)
 	{
 		img = purple_buddy_icon_data_new(icon_data, icon_len, NULL);
-		g_free(icon_data);
 	}
 
 	old_icon = g_strdup(purple_blist_node_get_string((PurpleBlistNode *)contact,