diff --git a/src/gfx_layout.cpp b/src/gfx_layout.cpp index 41dff33680..f34d9cb40f 100644 --- a/src/gfx_layout.cpp +++ b/src/gfx_layout.cpp @@ -8,7 +8,6 @@ /** @file gfx_layout.cpp Handling of laying out text. */ #include "stdafx.h" -#include "core/alloc_func.hpp" #include "core/math_func.hpp" #include "gfx_layout.h" #include "string_func.h" @@ -64,15 +63,15 @@ Font::Font(FontSize size, TextColour colour) : template static inline void GetLayouter(Layouter::LineCacheItem &line, std::string_view str, FontState &state) { - free(line.buffer); + typename T::CharType *buff_begin = new typename T::CharType[str.size() + 1]; + /* Move ownership of buff_begin into the Buffer/unique_ptr. */ + line.buffer = Layouter::LineCacheItem::Buffer(buff_begin, [](void *p) { delete[] reinterpret_cast(p); }); - typename T::CharType *buff_begin = MallocT(str.size() + 1); const typename T::CharType *buffer_last = buff_begin + str.size() + 1; typename T::CharType *buff = buff_begin; FontMap &font_mapping = line.runs; Font *f = Layouter::GetFont(state.fontsize, state.cur_colour); - line.buffer = buff_begin; font_mapping.clear(); auto cur = str.begin(); diff --git a/src/gfx_layout.h b/src/gfx_layout.h index 10f584e6d5..e6f91e4d7f 100644 --- a/src/gfx_layout.h +++ b/src/gfx_layout.h @@ -166,15 +166,14 @@ class Layouter : public std::vector; /* Stuff that cannot be freed until the ParagraphLayout is freed */ - void *buffer; ///< Accessed by our ParagraphLayout::nextLine. + Buffer buffer{nullptr, [](void *){}}; ///< Accessed by our ParagraphLayout::nextLine. FontMap runs; ///< Accessed by our ParagraphLayout::nextLine. FontState state_after; ///< Font state after the line. std::unique_ptr layout = nullptr; ///< Layout of the line. - - LineCacheItem() : buffer(nullptr) {} - ~LineCacheItem() { free(buffer); } }; private: typedef std::map LineCache;