aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-15 19:52:32 +0200
committerMax Kellermann <max@duempel.org>2012-08-15 23:10:00 +0200
commit2bd344549b5cfcb6d9a1e1e092c034e68d3071bc (patch)
tree26ce785fc374cdad0ba1ed3e09ad6c4329ddcb68 /src
parente96779de48be1f1b0080a8e1cfa89756c40e562d (diff)
downloadmpd-2bd344549b5cfcb6d9a1e1e092c034e68d3071bc.tar.gz
mpd-2bd344549b5cfcb6d9a1e1e092c034e68d3071bc.tar.xz
mpd-2bd344549b5cfcb6d9a1e1e092c034e68d3071bc.zip
queue: duplicate all song objects
Make sure the queue "owns" all song objects, so nobody else can free them.
Diffstat (limited to '')
-rw-r--r--src/queue.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/queue.c b/src/queue.c
index cd932875e..2a489242c 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -103,7 +103,7 @@ queue_append(struct queue *queue, struct song *song)
assert(!queue_is_full(queue));
queue->items[queue->length] = (struct queue_item){
- .song = song,
+ .song = song_dup_detached(song),
.id = id,
.version = queue->version,
.priority = 0,
@@ -256,8 +256,8 @@ queue_delete(struct queue *queue, unsigned position)
assert(position < queue->length);
song = queue_get(queue, position);
- if (!song_in_database(song))
- song_free(song);
+ assert(!song_in_database(song) || song_is_detached(song));
+ song_free(song);
id = queue_position_to_id(queue, position);
order = queue_position_to_order(queue, position);
@@ -291,8 +291,9 @@ queue_clear(struct queue *queue)
for (unsigned i = 0; i < queue->length; i++) {
struct queue_item *item = &queue->items[i];
- if (!song_in_database(item->song))
- song_free(item->song);
+ assert(!song_in_database(item->song) ||
+ song_is_detached(item->song));
+ song_free(item->song);
queue->id_to_position[item->id] = -1;
}