aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-19 11:37:42 +0100
committerMax Kellermann <max@duempel.org>2014-01-19 11:37:42 +0100
commit738d6f10409037fbf8aa30cec5aceb121e21e230 (patch)
treedae34c32150de1148b88df9599a365414b78e507 /src
parentba372197fbda68d72857585008061ca5f781f805 (diff)
downloadmpd-738d6f10409037fbf8aa30cec5aceb121e21e230.tar.gz
mpd-738d6f10409037fbf8aa30cec5aceb121e21e230.tar.xz
mpd-738d6f10409037fbf8aa30cec5aceb121e21e230.zip
db/proxy: simplify error handling in GetSong()
Check mpd_response_finish() before using mpd_song. Don't skip this check even if the mpd_song is non-nullptr.
Diffstat (limited to 'src')
-rw-r--r--src/db/ProxyDatabasePlugin.cxx20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/db/ProxyDatabasePlugin.cxx b/src/db/ProxyDatabasePlugin.cxx
index 4b44d9a87..e5e9ac76f 100644
--- a/src/db/ProxyDatabasePlugin.cxx
+++ b/src/db/ProxyDatabasePlugin.cxx
@@ -440,22 +440,20 @@ ProxyDatabase::GetSong(const char *uri, Error &error) const
}
struct mpd_song *song = mpd_recv_song(connection);
- Song *song2 = song != nullptr
- ? Convert(song)
- : nullptr;
- if (song != nullptr)
- mpd_song_free(song);
- if (!mpd_response_finish(connection)) {
- if (song2 != nullptr)
- song2->Free();
-
- CheckError(connection, error);
+ if (!mpd_response_finish(connection) &&
+ !CheckError(connection, error)) {
+ if (song != nullptr)
+ mpd_song_free(song);
return nullptr;
}
- if (song2 == nullptr)
+ if (song == nullptr) {
error.Format(db_domain, DB_NOT_FOUND, "No such song: %s", uri);
+ return nullptr;
+ }
+ Song *song2 = Convert(song);
+ mpd_song_free(song);
return song2;
}