1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-24 06:15:07 +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:
Andreas Kling 2019-05-29 06:31:28 +02:00
parent 1c4882892c
commit 6785250f8c

View file

@ -287,7 +287,7 @@ void* realloc(void* ptr, size_t size)
auto* header = (const CommonHeader*)page_base; auto* header = (const CommonHeader*)page_base;
old_size = header->m_size; old_size = header->m_size;
if (size == old_size) if (malloc_good_size(size) == old_size)
return ptr; return ptr;
auto* new_ptr = malloc(size); auto* new_ptr = malloc(size);
memcpy(new_ptr, ptr, min(old_size, size)); memcpy(new_ptr, ptr, min(old_size, size));