diff --git a/src/db/DatabaseSong.cxx b/src/db/DatabaseSong.cxx index 887794d25..aadc0bee4 100644 --- a/src/db/DatabaseSong.cxx +++ b/src/db/DatabaseSong.cxx @@ -23,6 +23,7 @@ #include "Interface.hxx" #include "DetachedSong.hxx" #include "storage/StorageInterface.hxx" +#include "util/ScopeExit.hxx" #include @@ -46,8 +47,7 @@ DatabaseDetachSong(const Database &db, const Storage &storage, const char *uri) const LightSong *tmp = db.GetSong(uri); assert(tmp != nullptr); - DetachedSong *song = new DetachedSong(DatabaseDetachSong(storage, - *tmp)); - db.ReturnSong(tmp); - return song; + AtScopeExit(&db, tmp) { db.ReturnSong(tmp); }; + + return new DetachedSong(DatabaseDetachSong(storage, *tmp)); }