diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mpdclient.c | 8 | ||||
-rw-r--r-- | src/playlist.c | 25 | ||||
-rw-r--r-- | src/playlist.h | 7 |
3 files changed, 34 insertions, 6 deletions
diff --git a/src/mpdclient.c b/src/mpdclient.c index 1d52aebdb..8449ca42b 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -163,7 +163,7 @@ mpdclient_new(void) mpdclient_t *c; c = g_malloc0(sizeof(mpdclient_t)); - c->playlist.list = g_array_sized_new(FALSE, FALSE, sizeof(struct mpd_song *), 1024); + playlist_init(&c->playlist); return c; } @@ -172,6 +172,9 @@ mpdclient_t * mpdclient_free(mpdclient_t *c) { mpdclient_disconnect(c); + + mpdclient_playlist_free(&c->playlist); + g_list_free(c->error_callbacks); g_list_free(c->playlist_callbacks); g_list_free(c->browse_callbacks); @@ -191,8 +194,7 @@ mpdclient_disconnect(mpdclient_t *c) mpd_freeStatus(c->status); c->status = NULL; - if (c->playlist.list) - mpdclient_playlist_free(&c->playlist); + playlist_clear(&c->playlist); if (c->song) c->song = NULL; diff --git a/src/playlist.c b/src/playlist.c index e2530435e..b600343d7 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -29,8 +29,17 @@ #define MPD_ERROR(c) (c==NULL || c->connection==NULL || c->connection->error) -gint -mpdclient_playlist_free(mpdclient_playlist_t *playlist) +void +playlist_init(struct mpdclient_playlist *playlist) +{ + playlist->id = 0; + playlist->updated = FALSE; + playlist->list = g_array_sized_new(FALSE, FALSE, + sizeof(struct mpd_song *), 1024); +} + +void +playlist_clear(struct mpdclient_playlist *playlist) { guint i; @@ -39,7 +48,17 @@ mpdclient_playlist_free(mpdclient_playlist_t *playlist) mpd_freeSong(song); } - g_array_free(playlist->list, TRUE); + g_array_set_size(playlist->list, 0); +} + +gint +mpdclient_playlist_free(mpdclient_playlist_t *playlist) +{ + if (playlist->list != NULL) { + playlist_clear(playlist); + g_array_free(playlist->list, TRUE); + } + memset(playlist, 0, sizeof(mpdclient_playlist_t)); return 0; } diff --git a/src/playlist.h b/src/playlist.h index 2d2a353a6..946ca631c 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -39,6 +39,13 @@ typedef struct mpdclient_playlist { GArray *list; } mpdclient_playlist_t; +void +playlist_init(struct mpdclient_playlist *playlist); + +/** remove and free all songs in the playlist */ +void +playlist_clear(struct mpdclient_playlist *playlist); + /* free a playlist */ gint mpdclient_playlist_free(mpdclient_playlist_t *playlist); |