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