From c68c3fa69cefe1f7f7981a6cc7fcba4d510d3f52 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 11 Jul 2021 13:23:13 +0200 Subject: [PATCH] AK: Use kfree_sized() in AK::StringImpl --- AK/StringImpl.cpp | 5 ----- AK/StringImpl.h | 9 ++++++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp index 3af1ce1eaca..0b27d60c498 100644 --- a/AK/StringImpl.cpp +++ b/AK/StringImpl.cpp @@ -37,11 +37,6 @@ StringImpl::~StringImpl() FlyString::did_destroy_impl({}, *this); } -static inline size_t allocation_size_for_stringimpl(size_t length) -{ - return sizeof(StringImpl) + (sizeof(char) * length) + sizeof(char); -} - NonnullRefPtr StringImpl::create_uninitialized(size_t length, char*& buffer) { VERIFY(length); diff --git a/AK/StringImpl.h b/AK/StringImpl.h index 219abdd5390..6e07c06919c 100644 --- a/AK/StringImpl.h +++ b/AK/StringImpl.h @@ -20,6 +20,8 @@ enum ShouldChomp { Chomp }; +size_t allocation_size_for_stringimpl(size_t length); + class StringImpl : public RefCounted { public: static NonnullRefPtr create_uninitialized(size_t length, char*& buffer); @@ -34,7 +36,7 @@ public: void operator delete(void* ptr) { - kfree(ptr); + kfree_sized(ptr, allocation_size_for_stringimpl(static_cast(ptr)->m_length)); } static StringImpl& the_empty_stringimpl(); @@ -100,6 +102,11 @@ private: char m_inline_buffer[0]; }; +inline size_t allocation_size_for_stringimpl(size_t length) +{ + return sizeof(StringImpl) + (sizeof(char) * length) + sizeof(char); +} + template<> struct Formatter : Formatter { void format(FormatBuilder& builder, const StringImpl& value)