From 966880eb45330bcdfbf4e0d74ad6e11b4782716c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 11 Jul 2021 14:01:46 +0200 Subject: [PATCH] AK: Don't use realloc() in AK::ByteBuffer This class is the only reason we have to support krealloc() in the kernel heap, something which adds a lot of complexity. Let's move towards a simpler path and do malloc+memset in the ByteBuffer code (where we know the sizes anyway.) --- AK/ByteBuffer.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h index 5f19d2b299..a6a4b9fe43 100644 --- a/AK/ByteBuffer.h +++ b/AK/ByteBuffer.h @@ -242,7 +242,9 @@ private: u8* new_buffer; new_capacity = kmalloc_good_size(new_capacity); if (!m_inline) { - new_buffer = (u8*)krealloc(m_outline_buffer, new_capacity); + new_buffer = (u8*)kmalloc(new_capacity); + if (m_outline_buffer) + __builtin_memcpy(new_buffer, m_outline_buffer, min(new_capacity, m_outline_capacity)); VERIFY(new_buffer); } else { new_buffer = (u8*)kmalloc(new_capacity);