From 3b8532f3fb379c7ecc6b64eecbbf9c824d18e875 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Aug 2012 23:28:19 +0200 Subject: DatabasePlugin: add method ReturnSong() Allow the plugin to allocate the GetSong() return value. --- src/db/SimpleDatabasePlugin.cxx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/db/SimpleDatabasePlugin.cxx') diff --git a/src/db/SimpleDatabasePlugin.cxx b/src/db/SimpleDatabasePlugin.cxx index c1de70d3e..94318f4e9 100644 --- a/src/db/SimpleDatabasePlugin.cxx +++ b/src/db/SimpleDatabasePlugin.cxx @@ -184,6 +184,10 @@ SimpleDatabase::Open(GError **error_r) root = directory_new_root(); mtime = 0; +#ifndef NDEBUG + borrowed_song_count = 0; +#endif + GError *error = NULL; if (!Load(&error)) { directory_free(root); @@ -204,6 +208,7 @@ void SimpleDatabase::Close() { assert(root != NULL); + assert(borrowed_song_count == 0); directory_free(root); } @@ -219,10 +224,25 @@ SimpleDatabase::GetSong(const char *uri, GError **error_r) const if (song == NULL) g_set_error(error_r, db_quark(), DB_NOT_FOUND, "No such song: %s", uri); +#ifndef NDEBUG + else + ++const_cast(borrowed_song_count); +#endif return song; } +void +SimpleDatabase::ReturnSong(gcc_unused struct song *song) const +{ + assert(song != nullptr); + +#ifndef NDEBUG + assert(borrowed_song_count > 0); + --const_cast(borrowed_song_count); +#endif +} + G_GNUC_PURE const struct directory * SimpleDatabase::LookupDirectory(const char *uri) const -- cgit v1.2.3