diff --git a/core/playlists/artist.c b/core/playlists/artist.c index 3084918e..2661ece0 100644 --- a/core/playlists/artist.c +++ b/core/playlists/artist.c @@ -31,7 +31,7 @@ static struct playlist *__artist_pl_alloc(struct artist *artist) static void __artist_pl_free(struct playlist *playlist) { if (playlist) { - queue_deinit(&playlist->pl_queue); + playlist_generic_deinit(playlist); g_free(playlist); } } diff --git a/core/playlists/generic.c b/core/playlists/generic.c index e72599c2..0143c407 100644 --- a/core/playlists/generic.c +++ b/core/playlists/generic.c @@ -47,6 +47,12 @@ void playlist_generic_init(struct playlist *playlist, struct queue_ops *ops) playlist->pl_private = NULL; } +void playlist_generic_deinit(struct playlist *playlist) +{ + if (playlist) + queue_deinit(&playlist->pl_queue); +} + void playlist_generic_save(struct playlist *playlist, struct file *file, unsigned int flags) { diff --git a/core/playlists/library.c b/core/playlists/library.c index 02a46599..f5e2f220 100644 --- a/core/playlists/library.c +++ b/core/playlists/library.c @@ -36,7 +36,7 @@ static struct playlist *__lib_pl_alloc(struct library *library) static void __lib_pl_free(struct playlist *playlist) { if (playlist) { - queue_deinit(&playlist->pl_queue); + playlist_generic_deinit(playlist); g_free(playlist); } } diff --git a/core/playlists/system.c b/core/playlists/system.c index c9050f6d..c2f3adb9 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -417,7 +417,7 @@ void pl_system_init(struct queue_ops *ops) void pl_system_deinit() { for (unsigned int i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) - queue_deinit(&pl_system_get(i)->pl_queue); + playlist_generic_deinit(pl_system_get(i)); } void pl_system_new_track(struct track *track) diff --git a/core/playlists/user.c b/core/playlists/user.c index da91647f..a1ef7fea 100644 --- a/core/playlists/user.c +++ b/core/playlists/user.c @@ -28,7 +28,7 @@ static struct db_entry *user_db_alloc(const gchar *name, unsigned int index) static void user_db_free(struct db_entry *dbe) { - queue_deinit(&USER_PLAYLIST(dbe)->pl_playlist.pl_queue); + playlist_generic_deinit(&USER_PLAYLIST(dbe)->pl_playlist); g_free(USER_PLAYLIST(dbe)->pl_playlist.pl_name); g_free(USER_PLAYLIST(dbe)); } diff --git a/core/queue.c b/core/queue.c index e7c3cc1d..0addb8dd 100644 --- a/core/queue.c +++ b/core/queue.c @@ -37,4 +37,7 @@ void queue_deinit(struct queue *queue) __queue_deinit(queue); g_slist_free(queue->q_sort); queue->q_sort = NULL; + queue->q_length = 0; + queue->q_cur.it_pos = UINT_MAX; + queue->q_cur.it_iter = NULL; } diff --git a/include/core/playlists/generic.h b/include/core/playlists/generic.h index c584c128..d7e299b7 100644 --- a/include/core/playlists/generic.h +++ b/include/core/playlists/generic.h @@ -38,6 +38,9 @@ void playlist_generic_set_callbacks(struct playlist_callbacks *); /* Generic playlist init function. */ void playlist_generic_init(struct playlist *, struct queue_ops *); +/* Generic playlist deinit function. */ +void playlist_generic_deinit(struct playlist *); + /* Generic playlist save function. */ void playlist_generic_save(struct playlist *, struct file *, unsigned int); diff --git a/tests/core/playlist.c b/tests/core/playlist.c index 7c1812da..b2d00a97 100644 --- a/tests/core/playlist.c +++ b/tests/core/playlist.c @@ -42,6 +42,8 @@ static void test_null() g_assert_null(playlist_new(PL_MAX_TYPE, NULL)); g_assert_false(playlist_delete(NULL)); + playlist_generic_deinit(NULL); + g_assert_null(playlist_lookup(PL_MAX_TYPE, "NULL")); g_assert_null(playlist_lookup(PL_MAX_TYPE, NULL)); g_assert_null(playlist_get(PL_MAX_TYPE, 0)); @@ -151,6 +153,14 @@ static void test_playlist() g_assert_cmpuint(p.pl_queue.q_length, ==, 0); g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX); g_assert_null(p.pl_queue.q_cur.it_iter); + + /* Deinitialize the playlist. */ + playlist_generic_deinit(&p); + g_assert_cmpuint(playlist_size(&p), ==, 0); + g_assert_cmpuint(p.pl_queue.q_length, ==, 0); + g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX); + g_assert_null(p.pl_queue.q_cur.it_iter); + g_assert_null(p.pl_queue.q_sort); } static void test_sorting() @@ -227,6 +237,14 @@ static void test_sorting() } for (i = 0; i < 13; i++) g_assert_cmpuint(queue_at(&p.pl_queue, i)->tr_track, ==, 13 - i); + + /* Deinitialize the playlist. */ + playlist_generic_deinit(&p); + g_assert_cmpuint(playlist_size(&p), ==, 0); + g_assert_cmpuint(p.pl_queue.q_length, ==, 0); + g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX); + g_assert_null(p.pl_queue.q_cur.it_iter); + g_assert_null(p.pl_queue.q_sort); } static void test_next() @@ -265,6 +283,14 @@ static void test_next() g_assert_cmpuint(playlist_next()->tr_track, ==, 6); g_assert_cmpuint(playlist_next()->tr_track, ==, 1); g_assert_cmpuint(playlist_size(&p), ==, 13); + + /* Deinitialize the playlist. */ + playlist_generic_deinit(&p); + g_assert_cmpuint(playlist_size(&p), ==, 0); + g_assert_cmpuint(p.pl_queue.q_length, ==, 0); + g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX); + g_assert_null(p.pl_queue.q_cur.it_iter); + g_assert_null(p.pl_queue.q_sort); } static void test_save_load() @@ -309,6 +335,13 @@ static void test_save_load() g_assert(queue_iter_val(&s.pl_queue.q_cur) == queue_at(&q.pl_queue, 4)); g_assert_cmpuint(g_slist_length(s.pl_queue.q_sort), ==, 0); g_assert_cmpuint(playlist_size(&s), ==, 13); + + /* Deinitialize the playlist. */ + playlist_generic_deinit(&p); + g_assert_cmpuint(playlist_size(&p), ==, 0); + g_assert_cmpuint(p.pl_queue.q_length, ==, 0); + g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX); + g_assert_null(p.pl_queue.q_cur.it_iter); } int main(int argc, char **argv)