diff --git a/src/filter/plugins/AutoConvertFilterPlugin.cxx b/src/filter/plugins/AutoConvertFilterPlugin.cxx index e3639e181..6ee2aae03 100644 --- a/src/filter/plugins/AutoConvertFilterPlugin.cxx +++ b/src/filter/plugins/AutoConvertFilterPlugin.cxx @@ -26,28 +26,26 @@ #include "AudioFormat.hxx" #include "util/ConstBuffer.hxx" +#include + #include class AutoConvertFilter final : public Filter { /** * The underlying filter. */ - Filter *const filter; + std::unique_ptr filter; /** * A convert_filter, just in case conversion is needed. nullptr * if unused. */ - Filter *const convert; + std::unique_ptr convert; public: - AutoConvertFilter(Filter *_filter, Filter *_convert) - :filter(_filter), convert(_convert) {} - - ~AutoConvertFilter() { - delete convert; - delete filter; - } + AutoConvertFilter(std::unique_ptr &&_filter, + std::unique_ptr &&_convert) + :filter(std::move(_filter)), convert(std::move(_convert)) {} virtual ConstBuffer FilterPCM(ConstBuffer src, Error &error) override; @@ -76,26 +74,25 @@ PreparedAutoConvertFilter::Open(AudioFormat &in_audio_format, Error &error) /* open the "real" filter */ AudioFormat child_audio_format = in_audio_format; - auto *new_filter = filter->Open(child_audio_format, error); - if (new_filter == nullptr) + std::unique_ptr new_filter(filter->Open(child_audio_format, error)); + if (!new_filter) return nullptr; /* need to convert? */ - Filter *convert = nullptr; + std::unique_ptr convert; if (in_audio_format != child_audio_format) { /* yes - create a convert_filter */ - convert = convert_filter_new(in_audio_format, - child_audio_format, - error); - if (convert == nullptr) { - delete new_filter; + convert.reset(convert_filter_new(in_audio_format, + child_audio_format, + error)); + if (!convert) return nullptr; - } } - return new AutoConvertFilter(new_filter, convert); + return new AutoConvertFilter(std::move(new_filter), + std::move(convert)); } ConstBuffer