diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/IcyMetaDataParser.cxx | 6 | ||||
-rw-r--r-- | src/IcyMetaDataParser.hxx | 14 | ||||
-rw-r--r-- | src/input/IcyInputStream.cxx | 4 |
3 files changed, 11 insertions, 13 deletions
diff --git a/src/IcyMetaDataParser.cxx b/src/IcyMetaDataParser.cxx index e39a7041c..0fe26afa3 100644 --- a/src/IcyMetaDataParser.cxx +++ b/src/IcyMetaDataParser.cxx @@ -39,7 +39,7 @@ IcyMetaDataParser::Reset() noexcept if (data_rest == 0 && meta_size > 0) delete[] meta_data; - delete tag; + tag.reset(); data_rest = data_size; meta_size = 0; @@ -209,9 +209,7 @@ IcyMetaDataParser::Meta(const void *data, size_t length) noexcept if (meta_position == meta_size) { /* parse */ - delete tag; - - tag = icy_parse_tag(meta_data, meta_data + meta_size).release(); + tag = icy_parse_tag(meta_data, meta_data + meta_size); delete[] meta_data; /* change back to normal data mode */ diff --git a/src/IcyMetaDataParser.hxx b/src/IcyMetaDataParser.hxx index 178a2e252..5460d4382 100644 --- a/src/IcyMetaDataParser.hxx +++ b/src/IcyMetaDataParser.hxx @@ -20,9 +20,11 @@ #ifndef MPD_ICY_META_DATA_PARSER_HXX #define MPD_ICY_META_DATA_PARSER_HXX -#include <stddef.h> +#include "tag/Tag.hxx" + +#include <memory> -struct Tag; +#include <stddef.h> class IcyMetaDataParser { size_t data_size = 0, data_rest; @@ -30,7 +32,7 @@ class IcyMetaDataParser { size_t meta_size, meta_position; char *meta_data; - Tag *tag; + std::unique_ptr<Tag> tag; public: ~IcyMetaDataParser() noexcept { @@ -81,10 +83,8 @@ public: */ size_t ParseInPlace(void *data, size_t length) noexcept; - Tag *ReadTag() noexcept { - Tag *result = tag; - tag = nullptr; - return result; + std::unique_ptr<Tag> ReadTag() noexcept { + return std::exchange(tag, nullptr); } }; diff --git a/src/input/IcyInputStream.cxx b/src/input/IcyInputStream.cxx index df9cbbb49..6933f8d3e 100644 --- a/src/input/IcyInputStream.cxx +++ b/src/input/IcyInputStream.cxx @@ -55,10 +55,10 @@ IcyInputStream::ReadTag() input_tag = new_input_tag; } - Tag *new_icy_tag = parser.ReadTag(); + auto new_icy_tag = parser.ReadTag(); if (new_icy_tag != nullptr) { delete icy_tag; - icy_tag = new_icy_tag; + icy_tag = new_icy_tag.release(); } if (new_input_tag == nullptr && new_icy_tag == nullptr) |