summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: eee102e)
raw | patch | inline | side by side (parent: eee102e)
author | Max Kellermann <max@duempel.org> | |
Tue, 16 Sep 2008 17:11:39 +0000 (19:11 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Tue, 16 Sep 2008 17:11:39 +0000 (19:11 +0200) |
Moved code from mpdclient_new() and mpdclient_playlist_free(). In
mpdclient_disconnect(), call mpdclient_playlist_clear() instead of
mpdclient_playlist_free() (which is now called in mpdclient_free()).
mpdclient_disconnect(), call mpdclient_playlist_clear() instead of
mpdclient_playlist_free() (which is now called in mpdclient_free()).
src/mpdclient.c | patch | blob | history | |
src/playlist.c | patch | blob | history | |
src/playlist.h | patch | blob | history |
diff --git a/src/mpdclient.c b/src/mpdclient.c
index 1d52aebdb196003f375fd91d1b7ba27cf9b04b08..8449ca42b464be4bdf675cb7b9174dd34a144405 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
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;
}
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);
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 e2530435e37bd432c1921cda53caebcc672d0ad0..b600343d720ab23fba3b1663b1ba539eedc554f4 100644 (file)
--- a/src/playlist.c
+++ b/src/playlist.c
#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;
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 2d2a353a68b9737f74845a46dabdaf9ec30a6ceb..946ca631c44b6138ec78d911f90510a9fb55894c 100644 (file)
--- a/src/playlist.h
+++ b/src/playlist.h
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);