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:
Andreas Kling 2019-05-29 06:31:28 +02:00
commit 6785250f8c
Notes: sideshowbarker 2024-07-19 13:51:19 +09:00

View file

@ -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));