From 896908b699c76879f290d0db3326e07dbcc21261 Mon Sep 17 00:00:00 2001 From: Jorg Schuler Date: Wed, 14 Nov 2007 15:02:08 +0000 Subject: * src/itdb_photoalbum.c (itdb_photodb_photoalbum_remove): make sure same photo isn't freed multiple times if it was added in an album multiple times. git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1782 f01d2545-417e-4e96-918e-98f8d0dbbcb6 --- ChangeLog | 8 ++++++-- src/itdb_photoalbum.c | 27 ++++++++++----------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2601357..4c3bd5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-11-14 Jorg Schuler + + * src/itdb_photoalbum.c (itdb_photodb_photoalbum_remove): make + sure same photo isn't freed multiple times if it was added in an + album multiple times. + 2007-11-13 Christophe Fergeau * src/itdb_photoalbum.c: fix bug in itdb_photodb_photoalbum_remove, @@ -5,8 +11,6 @@ erasing elements and iterating over the list at the same time, which resulted in the function not working properly -====== libgpod 0.6.0 ====== - 2007-11-10 Christophe Fergeau * Makefile.am: add README.SysInfo to EXTRADIST diff --git a/src/itdb_photoalbum.c b/src/itdb_photoalbum.c index 7656a64..e53686a 100644 --- a/src/itdb_photoalbum.c +++ b/src/itdb_photoalbum.c @@ -1,4 +1,4 @@ -/* Time-stamp: <2007-11-03 20:27:36 jcs> +/* | | Copyright (C) 2002-2006 Jorg Schuler | Part of the gtkpod project. @@ -678,8 +678,6 @@ void itdb_photodb_photoalbum_remove (Itdb_PhotoDB *db, Itdb_PhotoAlbum *album, gboolean remove_pics) { - GList *it; - g_return_if_fail (db); g_return_if_fail (album); @@ -687,21 +685,16 @@ void itdb_photodb_photoalbum_remove (Itdb_PhotoDB *db, * and remove them from the database */ if (remove_pics) { - GList *pics; - /* we can't let itdb_photodb_remove_photo modify album->members - * while we're iterating through it, that's it's moved to pics - * first. itdb_photodb_remove_photo frees the memory used - * by 'photo' so a g_list_free is all we have to do to free - * pics memory when we are done iterating - */ - pics = album->members; - album->members = NULL; - for (it = pics; it != NULL; it = it->next ) + /* we can't iterate over album->members because + itdb_photodb_remove_photo() modifies album->members in + a not easily predicable way (e.g. @photo may exist in the + album several times). Therefore we remove photos until + album->members is empty. */ + while (album->members) { - Itdb_Artwork *photo = it->data; - itdb_photodb_remove_photo (db, NULL, photo); - } - g_list_free (pics); + Itdb_Artwork *photo = album->members->data; + itdb_photodb_remove_photo (db, NULL, photo); + } } db->photoalbums = g_list_remove (db->photoalbums, album); itdb_photodb_photoalbum_free (album); -- cgit