aboutsummaryrefslogtreecommitdiffstats
path: root/src/songvec.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-10-21 01:35:11 +0200
committerMax Kellermann <max@duempel.org>2008-10-21 01:35:11 +0200
commitd52437d43f159bc03072bedcf2ac8aa7766be0ea (patch)
tree237298944250a54344b90a8df24d72576bc2411f /src/songvec.c
parent9aeacdef5631d5bab67e055a3aa56ba1390c2ea0 (diff)
downloadmpd-d52437d43f159bc03072bedcf2ac8aa7766be0ea.tar.gz
mpd-d52437d43f159bc03072bedcf2ac8aa7766be0ea.tar.xz
mpd-d52437d43f159bc03072bedcf2ac8aa7766be0ea.zip
update: fix multiple deletes from *vec iterators
{song,dir}vec_for_each each failed to gracefully handle deleted files when iterating through. While we were thread-safe, we were not safe within the calling thread. If a callback we passed caused sv->nr to shring, our index would still increment; causing files to stay in the database. A way to test this is to remove 10 or so contiguous songs from a >10 song directory.
Diffstat (limited to '')
-rw-r--r--src/songvec.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/songvec.c b/src/songvec.c
index 7b0607dd9..df600f92a 100644
--- a/src/songvec.c
+++ b/src/songvec.c
@@ -96,18 +96,22 @@ songvec_for_each(const struct songvec *sv,
int (*fn)(struct song *, void *), void *arg)
{
size_t i;
+ size_t prev_nr;
pthread_mutex_lock(&nr_lock);
- for (i = 0; i < sv->nr; ++i) {
+ for (i = 0; i < sv->nr; ) {
struct song *song = sv->base[i];
assert(song);
assert(*song->url);
+ prev_nr = sv->nr;
pthread_mutex_unlock(&nr_lock); /* fn() may block */
if (fn(song, arg) < 0)
return -1;
pthread_mutex_lock(&nr_lock); /* sv->nr may change in fn() */
+ if (prev_nr == sv->nr)
+ ++i;
}
pthread_mutex_unlock(&nr_lock);