summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/SongSave.cxx8
-rw-r--r--src/SongSave.hxx4
-rw-r--r--src/db/plugins/simple/DirectorySave.cxx3
-rw-r--r--src/queue/QueueSave.cxx9
4 files changed, 9 insertions, 15 deletions
diff --git a/src/SongSave.cxx b/src/SongSave.cxx
index eadb0c254..ab80c5c75 100644
--- a/src/SongSave.cxx
+++ b/src/SongSave.cxx
@@ -76,10 +76,10 @@ song_save(BufferedOutputStream &os, const DetachedSong &song)
os.Format(SONG_END "\n");
}
-DetachedSong *
+std::unique_ptr<DetachedSong>
song_load(TextFile &file, const char *uri)
{
- DetachedSong *song = new DetachedSong(uri);
+ auto song = std::make_unique<DetachedSong>(uri);
TagBuilder tag;
@@ -88,8 +88,6 @@ song_load(TextFile &file, const char *uri)
strcmp(line, SONG_END) != 0) {
char *colon = strchr(line, ':');
if (colon == nullptr || colon == line) {
- delete song;
-
throw FormatRuntimeError("unknown line in db: %s", line);
}
@@ -116,8 +114,6 @@ song_load(TextFile &file, const char *uri)
song->SetStartTime(SongTime::FromMS(start_ms));
song->SetEndTime(SongTime::FromMS(end_ms));
} else {
- delete song;
-
throw FormatRuntimeError("unknown line in db: %s", line);
}
}
diff --git a/src/SongSave.hxx b/src/SongSave.hxx
index d51c7c286..9e6ae151d 100644
--- a/src/SongSave.hxx
+++ b/src/SongSave.hxx
@@ -20,6 +20,8 @@
#ifndef MPD_SONG_SAVE_HXX
#define MPD_SONG_SAVE_HXX
+#include <memory>
+
#define SONG_BEGIN "song_begin: "
struct Song;
@@ -39,7 +41,7 @@ song_save(BufferedOutputStream &os, const DetachedSong &song);
*
* Throws #std::runtime_error on error.
*/
-DetachedSong *
+std::unique_ptr<DetachedSong>
song_load(TextFile &file, const char *uri);
#endif
diff --git a/src/db/plugins/simple/DirectorySave.cxx b/src/db/plugins/simple/DirectorySave.cxx
index d3f75a4d7..d27d208a5 100644
--- a/src/db/plugins/simple/DirectorySave.cxx
+++ b/src/db/plugins/simple/DirectorySave.cxx
@@ -160,11 +160,10 @@ directory_load(TextFile &file, Directory &directory)
if (directory.FindSong(name) != nullptr)
throw FormatRuntimeError("Duplicate song '%s'", name);
- DetachedSong *song = song_load(file, name);
+ auto song = song_load(file, name);
directory.AddSong(Song::NewFrom(std::move(*song),
directory));
- delete song;
} else if ((p = StringAfterPrefix(line, PLAYLIST_META_BEGIN))) {
const char *name = p;
playlist_metadata_load(file, directory.playlists, name);
diff --git a/src/queue/QueueSave.cxx b/src/queue/QueueSave.cxx
index a03d4950e..af29b62b3 100644
--- a/src/queue/QueueSave.cxx
+++ b/src/queue/QueueSave.cxx
@@ -89,7 +89,7 @@ queue_load_song(TextFile &file, const SongLoader &loader,
return;
}
- DetachedSong *song;
+ std::unique_ptr<DetachedSong> song;
if ((p = StringAfterPrefix(line, SONG_BEGIN))) {
const char *uri = p;
@@ -111,14 +111,11 @@ queue_load_song(TextFile &file, const SongLoader &loader,
const char *uri = endptr + 1;
- song = new DetachedSong(uri);
+ song = std::make_unique<DetachedSong>(uri);
}
- if (!playlist_check_translate_song(*song, nullptr, loader)) {
- delete song;
+ if (playlist_check_translate_song(*song, nullptr, loader))
return;
- }
queue.Append(std::move(*song), priority);
- delete song;
}