diff options
author | Max Kellermann <max@duempel.org> | 2012-08-15 19:52:32 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-08-15 23:10:00 +0200 |
commit | 2bd344549b5cfcb6d9a1e1e092c034e68d3071bc (patch) | |
tree | 26ce785fc374cdad0ba1ed3e09ad6c4329ddcb68 /src/queue.c | |
parent | e96779de48be1f1b0080a8e1cfa89756c40e562d (diff) |
queue: duplicate all song objects
Make sure the queue "owns" all song objects, so nobody else can free
them.
Diffstat (limited to 'src/queue.c')
-rw-r--r-- | src/queue.c | 11 |
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; } |