diff --git a/src/decoder/DecoderControl.cxx b/src/decoder/DecoderControl.cxx index 1451b1552..55ed7b8ae 100644 --- a/src/decoder/DecoderControl.cxx +++ b/src/decoder/DecoderControl.cxx @@ -38,8 +38,6 @@ DecoderControl::DecoderControl(Mutex &_mutex, Cond &_client_cond, DecoderControl::~DecoderControl() noexcept { ClearError(); - - delete song; } void @@ -92,7 +90,7 @@ DecoderControl::IsCurrentSong(const DetachedSong &_song) const noexcept } void -DecoderControl::Start(DetachedSong *_song, +DecoderControl::Start(std::unique_ptr _song, SongTime _start_time, SongTime _end_time, MusicBuffer &_buffer, MusicPipe &_pipe) noexcept { @@ -101,8 +99,7 @@ DecoderControl::Start(DetachedSong *_song, assert(_song != nullptr); assert(_pipe.IsEmpty()); - delete song; - song = _song; + song = std::move(_song); start_time = _start_time; end_time = _end_time; buffer = &_buffer; diff --git a/src/decoder/DecoderControl.hxx b/src/decoder/DecoderControl.hxx index 5a92c35ec..755adae73 100644 --- a/src/decoder/DecoderControl.hxx +++ b/src/decoder/DecoderControl.hxx @@ -31,8 +31,8 @@ #include "ReplayGainMode.hxx" #include - #include +#include #include #include @@ -130,11 +130,8 @@ struct DecoderControl { * The song currently being decoded. This attribute is set by * the player thread, when it sends the #DecoderCommand::START * command. - * - * This is a duplicate, and must be freed when this attribute - * is cleared. */ - DetachedSong *song = nullptr; + std::unique_ptr song; /** * The initial seek position, e.g. to the start of a sub-track @@ -382,7 +379,8 @@ public: * @param pipe the pipe which receives the decoded chunks (owned by * the caller) */ - void Start(DetachedSong *song, SongTime start_time, SongTime end_time, + void Start(std::unique_ptr song, + SongTime start_time, SongTime end_time, MusicBuffer &buffer, MusicPipe &pipe) noexcept; void Stop() noexcept; diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index b9ffb281f..efbcfedd0 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -360,7 +360,7 @@ Player::StartDecoder(MusicPipe &_pipe) SongTime start_time = pc.next_song->GetStartTime() + pc.seek_time; - dc.Start(new DetachedSong(*pc.next_song), + dc.Start(std::make_unique(*pc.next_song), start_time, pc.next_song->GetEndTime(), buffer, _pipe); }