queue: duplicate all song objects
Make sure the queue "owns" all song objects, so nobody else can free them.
This commit is contained in:
parent
e96779de48
commit
2bd344549b
@ -1351,6 +1351,7 @@ test_test_pcm_LDADD = \
|
|||||||
|
|
||||||
test_test_queue_priority_SOURCES = \
|
test_test_queue_priority_SOURCES = \
|
||||||
src/queue.c \
|
src/queue.c \
|
||||||
|
test/FakeSong.cxx \
|
||||||
test/test_queue_priority.c
|
test/test_queue_priority.c
|
||||||
test_test_queue_priority_LDADD = \
|
test_test_queue_priority_LDADD = \
|
||||||
$(GLIB_LIBS)
|
$(GLIB_LIBS)
|
||||||
|
11
src/queue.c
11
src/queue.c
@ -103,7 +103,7 @@ queue_append(struct queue *queue, struct song *song)
|
|||||||
assert(!queue_is_full(queue));
|
assert(!queue_is_full(queue));
|
||||||
|
|
||||||
queue->items[queue->length] = (struct queue_item){
|
queue->items[queue->length] = (struct queue_item){
|
||||||
.song = song,
|
.song = song_dup_detached(song),
|
||||||
.id = id,
|
.id = id,
|
||||||
.version = queue->version,
|
.version = queue->version,
|
||||||
.priority = 0,
|
.priority = 0,
|
||||||
@ -256,8 +256,8 @@ queue_delete(struct queue *queue, unsigned position)
|
|||||||
assert(position < queue->length);
|
assert(position < queue->length);
|
||||||
|
|
||||||
song = queue_get(queue, position);
|
song = queue_get(queue, position);
|
||||||
if (!song_in_database(song))
|
assert(!song_in_database(song) || song_is_detached(song));
|
||||||
song_free(song);
|
song_free(song);
|
||||||
|
|
||||||
id = queue_position_to_id(queue, position);
|
id = queue_position_to_id(queue, position);
|
||||||
order = queue_position_to_order(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++) {
|
for (unsigned i = 0; i < queue->length; i++) {
|
||||||
struct queue_item *item = &queue->items[i];
|
struct queue_item *item = &queue->items[i];
|
||||||
|
|
||||||
if (!song_in_database(item->song))
|
assert(!song_in_database(item->song) ||
|
||||||
song_free(item->song);
|
song_is_detached(item->song));
|
||||||
|
song_free(item->song);
|
||||||
|
|
||||||
queue->id_to_position[item->id] = -1;
|
queue->id_to_position[item->id] = -1;
|
||||||
}
|
}
|
||||||
|
33
test/FakeSong.cxx
Normal file
33
test/FakeSong.cxx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user