From 5d8e75872431a60bbb977b066d9cb939e1115d14 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Mon, 2 Dec 2019 01:34:44 +0100 Subject: [PATCH] Plugging leaks --- src/sfizz/Buffer.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/sfizz/Buffer.h b/src/sfizz/Buffer.h index 0cab3d9b..60b53e19 100644 --- a/src/sfizz/Buffer.h +++ b/src/sfizz/Buffer.h @@ -149,12 +149,15 @@ public: */ Buffer(Buffer&& other) { - largerSize = std::exchange(other.largerSize, 0); - alignedSize = std::exchange(other.alignedSize, 0); - paddedData = std::exchange(other.paddedData, nullptr); - normalData = std::exchange(other.normalData, nullptr); - normalEnd = std::exchange(other.normalEnd, nullptr); - _alignedEnd = std::exchange(other._alignedEnd, nullptr); + if (this != &other) { + std::free(paddedData); + largerSize = std::exchange(other.largerSize, 0); + alignedSize = std::exchange(other.alignedSize, 0); + paddedData = std::exchange(other.paddedData, nullptr); + normalData = std::exchange(other.normalData, nullptr); + normalEnd = std::exchange(other.normalEnd, nullptr); + _alignedEnd = std::exchange(other._alignedEnd, nullptr); + } } Buffer& operator=(const Buffer& other) @@ -188,6 +191,7 @@ public: constexpr iterator end() noexcept { return normalEnd; } constexpr pointer alignedEnd() noexcept { return _alignedEnd; } + private: static constexpr auto AlignmentMask { Alignment - 1 }; static constexpr auto TypeAlignment { Alignment / sizeof(value_type) };