summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-07-11 13:23:13 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-11 14:14:51 +0200
commitc68c3fa69cefe1f7f7981a6cc7fcba4d510d3f52 (patch)
treebee5b8709f6ba77978798dada30d986e99949496
parent3aabace9f5e887ccba61e47fa0133a3d47b6d97b (diff)
downloadserenity-c68c3fa69cefe1f7f7981a6cc7fcba4d510d3f52.zip
AK: Use kfree_sized() in AK::StringImpl
-rw-r--r--AK/StringImpl.cpp5
-rw-r--r--AK/StringImpl.h9
2 files changed, 8 insertions, 6 deletions
diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp
index 3af1ce1eac..0b27d60c49 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> StringImpl::create_uninitialized(size_t length, char*& buffer)
{
VERIFY(length);
diff --git a/AK/StringImpl.h b/AK/StringImpl.h
index 219abdd539..6e07c06919 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<StringImpl> {
public:
static NonnullRefPtr<StringImpl> 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<StringImpl*>(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<StringImpl> : Formatter<StringView> {
void format(FormatBuilder& builder, const StringImpl& value)