From 38d024c6f3d55f1ffbb1597c563ad0ee1625b09f Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sun, 29 Dec 2024 23:38:15 +0100 Subject: Fix use of aligned_alloc on Linux --- asl/allocator.cpp | 4 ++-- asl/buffer.hpp | 1 + asl/tests/format_tests.cpp | 14 +++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'asl') diff --git a/asl/allocator.cpp b/asl/allocator.cpp index 645dd22..5dbdce0 100644 --- a/asl/allocator.cpp +++ b/asl/allocator.cpp @@ -18,8 +18,8 @@ void* asl::GlobalHeap::alloc(const layout& layout) static_cast(layout.align)); #elif ASL_OS_LINUX void* ptr = ::aligned_alloc( - static_cast(layout.size), - static_cast(layout.align)); + static_cast(layout.align), + static_cast(layout.size)); #endif ASL_ASSERT(ptr != nullptr); // @Todo panic return ptr; diff --git a/asl/buffer.hpp b/asl/buffer.hpp index 74465bd..12cbb80 100644 --- a/asl/buffer.hpp +++ b/asl/buffer.hpp @@ -117,6 +117,7 @@ public: // @Todo Destructor // @Todo clear // @Todo Copy/move constructor & assignment + // @Todo Do leak checks on Linux constexpr isize_t size() const { diff --git a/asl/tests/format_tests.cpp b/asl/tests/format_tests.cpp index 906fce6..042fcb4 100644 --- a/asl/tests/format_tests.cpp +++ b/asl/tests/format_tests.cpp @@ -12,6 +12,11 @@ class StringSink : public asl::Writer char* m_data{}; public: + ~StringSink() + { + reset(); + } + void write(asl::span str) override { m_data = reinterpret_cast(asl::GlobalHeap::realloc( @@ -28,9 +33,12 @@ public: void reset() { - m_current_len = 0; - asl::GlobalHeap::dealloc(m_data, asl::layout::array(m_current_len)); - m_data = nullptr; + if (m_data != nullptr) + { + m_current_len = 0; + asl::GlobalHeap::dealloc(m_data, asl::layout::array(m_current_len)); + m_data = nullptr; + } } }; -- cgit