Commit 2bd34454 authored by Max Kellermann's avatar Max Kellermann

queue: duplicate all song objects

Make sure the queue "owns" all song objects, so nobody else can free them.
parent e96779de
......@@ -1351,6 +1351,7 @@ test_test_pcm_LDADD = \
test_test_queue_priority_SOURCES = \
src/queue.c \
test/FakeSong.cxx \
test/test_queue_priority.c
test_test_queue_priority_LDADD = \
$(GLIB_LIBS)
......
......@@ -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;
}
......
/*
* Copyright (C) 2003-2012 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "song.h"
#include "directory.h"
#include "gcc.h"
#include <stdlib.h>
struct directory detached_root;
struct song *
song_dup_detached(gcc_unused const struct song *src)
{
abort();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment