Mercurial > pidgin.yaz
changeset 16383:05033ae856b2
Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Tue, 24 Apr 2007 19:12:48 +0000 |
parents | 5f6abf3a5369 |
children | 54ea8863b8e8 |
files | libpurple/buddyicon.c pidgin/gtkblist.c pidgin/gtkconv.c |
diffstat | 3 files changed, 20 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/buddyicon.c Tue Apr 24 17:00:51 2007 +0000 +++ b/libpurple/buddyicon.c Tue Apr 24 19:12:48 2007 +0000 @@ -62,7 +62,6 @@ g_return_if_fail(filename != NULL); refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename)); - printf("refs before increment = %d\n", refs); g_hash_table_insert(icon_file_cache, g_strdup(filename), GINT_TO_POINTER(refs + 1)); @@ -77,7 +76,6 @@ return; refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename)); - printf("refs before decrement = %d\n", refs); if (refs == 1) { @@ -176,26 +174,21 @@ /* It's possible that there are other references to this icon * cache file that are not currently loaded into memory. */ - printf("file has %d refs\n", GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename))); if (GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename))) return; dirname = purple_buddy_icons_get_cache_dir(); path = g_build_filename(dirname, filename, NULL); - printf("Going to unlink %s\n", path); if (g_file_test(path, G_FILE_TEST_EXISTS)) { if (g_unlink(path)) { - printf("Failed to unlink %s\n", path); - purple_debug_error("buddyicon", "Failed to delete %s: %s\n", path, strerror(errno)); } else { - printf("Unlinked %s\n", path); purple_debug_info("buddyicon", "Deleted cache file: %s\n", path); } } @@ -203,6 +196,12 @@ g_free(path); } +gboolean +value_equals(gpointer key, gpointer value, gpointer user_data) +{ + return (value == user_data); +} + static void image_deleting_cb(PurpleStoredImage *img, gpointer data) { @@ -212,6 +211,10 @@ { purple_buddy_icon_data_uncache_file(filename); g_hash_table_remove(icon_data_cache, filename); + + /* We could make this O(1) by using another hash table, but + * this is probably good enough. */ + g_hash_table_foreach_remove(custom_icon_cache, value_equals, img); } } @@ -385,14 +388,12 @@ purple_blist_node_set_string((PurpleBlistNode *)buddy, "buddy_icon", filename); - printf("Calling ref_filename(%s)\n", filename); ref_filename(filename); } else { purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "buddy_icon"); } - printf("Calling unref_filename(%s)\n", old_icon); unref_filename(old_icon); g_free(old_icon); } @@ -418,10 +419,8 @@ if (data != NULL && len > 0) icon->img = purple_buddy_icon_data_new(data, len, NULL); - printf("Calling purple_buddy_icon_update\n"); purple_buddy_icon_update(icon); - printf("Calling purple_imgstore_unref\n"); purple_imgstore_unref(old_img); } @@ -815,8 +814,9 @@ purple_blist_node_remove_setting(node, "buddy_icon"); } + else + ref_filename(filename); g_free(path); - ref_filename(filename); } } } @@ -841,8 +841,9 @@ purple_blist_node_remove_setting(node, "custom_buddy_icon"); } + else + ref_filename(filename); g_free(path); - ref_filename(filename); } } }
--- a/pidgin/gtkblist.c Tue Apr 24 17:00:51 2007 +0000 +++ b/pidgin/gtkblist.c Tue Apr 24 19:12:48 2007 +0000 @@ -2215,14 +2215,14 @@ loader = gdk_pixbuf_loader_new(); gdk_pixbuf_loader_write(loader, data, len, NULL); gdk_pixbuf_loader_close(loader, NULL); + + purple_imgstore_unref(custom_img); + buf = gdk_pixbuf_loader_get_pixbuf(loader); if (buf) g_object_ref(G_OBJECT(buf)); g_object_unref(G_OBJECT(loader)); - // TODO: FIX THIS!!! - //purple_imgstore_unref(custom_img); - if (buf) { int orig_width, orig_height; int scale_width, scale_height;
--- a/pidgin/gtkconv.c Tue Apr 24 17:00:51 2007 +0000 +++ b/pidgin/gtkconv.c Tue Apr 24 19:12:48 2007 +0000 @@ -6259,14 +6259,14 @@ loader = gdk_pixbuf_loader_new(); gdk_pixbuf_loader_write(loader, data, len, NULL); gdk_pixbuf_loader_close(loader, &err); + + purple_imgstore_unref(custom_img); + anim = gdk_pixbuf_loader_get_animation(loader); if (anim) g_object_ref(G_OBJECT(anim)); g_object_unref(loader); - // TODO: FIX THIS!!! - //purple_imgstore_unref(custom_img); - if (!anim) return; gtkconv->u.im->anim = anim;