SongLoader: use temporary stack variable, no heap allocation

Improved exception-safety.
This commit is contained in:
Max Kellermann 2016-02-28 11:08:00 +01:00
parent 9de984f7f8
commit fe4b1f96f1

View File

@ -65,15 +65,14 @@ SongLoader::LoadFile(const char *path_utf8, Path path_fs, Error &error) const
} }
#endif #endif
DetachedSong *song = new DetachedSong(path_utf8); DetachedSong song(path_utf8);
if (!song->LoadFile(path_fs)) { if (!song.LoadFile(path_fs)) {
error.Set(playlist_domain, int(PlaylistResult::NO_SUCH_SONG), error.Set(playlist_domain, int(PlaylistResult::NO_SUCH_SONG),
"No such file"); "No such file");
delete song;
return nullptr; return nullptr;
} }
return song; return new DetachedSong(std::move(song));
} }
DetachedSong * DetachedSong *