ac9f7f0
Index: ChangeLog
ac9f7f0
===================================================================
ac9f7f0
--- ChangeLog	(revision 1778)
ac9f7f0
+++ ChangeLog	(revision 1785)
ac9f7f0
@@ -1,5 +1,21 @@
ac9f7f0
-====== libgpod 0.6.0 ======
ac9f7f0
+2007-11-14  Christophe <teuf@gnome.org>
ac9f7f0
 
ac9f7f0
+	* src/itdb_photoalbum.c: use g_list_remove all instead of an
ac9f7f0
+	inefficient combination of g_list_find + g_list_remove
ac9f7f0
+
ac9f7f0
+2007-11-14  Jorg Schuler <jcsjcs at users.sourceforge.net>
ac9f7f0
+
ac9f7f0
+	* src/itdb_photoalbum.c (itdb_photodb_photoalbum_remove): make
ac9f7f0
+	  sure same photo isn't freed multiple times if it was added in an
ac9f7f0
+	  album multiple times.
ac9f7f0
+
ac9f7f0
+2007-11-13  Christophe Fergeau <teuf@gnome.org>
ac9f7f0
+
ac9f7f0
+	* src/itdb_photoalbum.c: fix bug in itdb_photodb_photoalbum_remove,
ac9f7f0
+	when removing all the photos from the photodatabase, we were
ac9f7f0
+	erasing elements and iterating over the list at the same time,
ac9f7f0
+	which resulted in the function not working properly
ac9f7f0
+
ac9f7f0
 2007-11-10  Christophe Fergeau <teuf@gnome.org>
ac9f7f0
 
ac9f7f0
 	* Makefile.am: add README.SysInfo to EXTRADIST
ac9f7f0
Index: src/itdb_photoalbum.c
ac9f7f0
===================================================================
ac9f7f0
--- src/itdb_photoalbum.c	(revision 1778)
ac9f7f0
+++ src/itdb_photoalbum.c	(revision 1785)
ac9f7f0
@@ -1,4 +1,4 @@
ac9f7f0
-/* Time-stamp: <2007-11-03 20:27:36 jcs>
ac9f7f0
+/*
ac9f7f0
 |
ac9f7f0
 |  Copyright (C) 2002-2006 Jorg Schuler <jcsjcs at users sourceforge net>
ac9f7f0
 |  Part of the gtkpod project.
ac9f7f0
@@ -615,10 +615,7 @@
ac9f7f0
         for (it = db->photoalbums; it != NULL; it = it->next)
ac9f7f0
 	{
ac9f7f0
             Itdb_PhotoAlbum *_album = it->data;
ac9f7f0
-	    while (g_list_find (_album->members, photo))
ac9f7f0
-	    {
ac9f7f0
-		_album->members = g_list_remove (_album->members, photo);
ac9f7f0
-	    }
ac9f7f0
+            _album->members = g_list_remove_all (_album->members, photo);
ac9f7f0
         }
ac9f7f0
         /* Remove the photo from the image list */
ac9f7f0
 	db->photos = g_list_remove (db->photos, photo);
ac9f7f0
@@ -678,8 +675,6 @@
ac9f7f0
 				     Itdb_PhotoAlbum *album,
ac9f7f0
 				     gboolean remove_pics)
ac9f7f0
 {
ac9f7f0
-        GList *it;
ac9f7f0
-
ac9f7f0
         g_return_if_fail (db);
ac9f7f0
         g_return_if_fail (album);
ac9f7f0
 
ac9f7f0
@@ -687,11 +682,16 @@
ac9f7f0
 	 * and remove them from the database */
ac9f7f0
         if (remove_pics)
ac9f7f0
 	{
ac9f7f0
-            for (it = album->members; it != NULL; it = it->next )
ac9f7f0
+	    /* we can't iterate over album->members because
ac9f7f0
+	       itdb_photodb_remove_photo() modifies album->members in
ac9f7f0
+	       a not easily predicable way (e.g. @photo may exist in the
ac9f7f0
+	       album several times). Therefore we remove photos until
ac9f7f0
+	       album->members is empty. */
ac9f7f0
+	    while (album->members)
ac9f7f0
 	    {
ac9f7f0
-                Itdb_Artwork *photo = it->data;
ac9f7f0
-                itdb_photodb_remove_photo (db, NULL, photo);
ac9f7f0
-            }
ac9f7f0
+		Itdb_Artwork *photo = album->members->data;
ac9f7f0
+		itdb_photodb_remove_photo (db, NULL, photo);
ac9f7f0
+	    }
ac9f7f0
         }
ac9f7f0
         db->photoalbums = g_list_remove (db->photoalbums, album);
ac9f7f0
 	itdb_photodb_photoalbum_free (album);