mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibC: realloc() should reuse the existing allocation more often.
We were only reusing the existing allocation if the new requested size was exactly the same as the fudged size of the block. This meant that realloc() could allocate a new block even though the new block would be identical to the old block.
This commit is contained in:
@@ -287,7 +287,7 @@ void* realloc(void* ptr, size_t size)
|
||||
auto* header = (const CommonHeader*)page_base;
|
||||
old_size = header->m_size;
|
||||
|
||||
if (size == old_size)
|
||||
if (malloc_good_size(size) == old_size)
|
||||
return ptr;
|
||||
auto* new_ptr = malloc(size);
|
||||
memcpy(new_ptr, ptr, min(old_size, size));
|
||||
|
||||
Reference in New Issue
Block a user