Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mem/slab.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace snmalloc

meta.debug_slab_invariant(is_short(), this);

if (zero_mem == YesZero)
if constexpr (zero_mem == YesZero)
{
if (rsize < PAGE_ALIGNED_SIZE)
memory_provider.zero(p, rsize);
Expand Down
10 changes: 7 additions & 3 deletions src/override/malloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ extern "C"
"Calling realloc on pointer that is not to the start of an allocation");
}
#endif
size_t sz = Alloc::alloc_size(ptr);
// Keep the current allocation if the given size is in the same sizeclass.
if (sz == sizeclass_to_size(size_to_sizeclass(size)))
return ptr;

void* p = SNMALLOC_NAME_MANGLE(malloc)(size);
if (p)
if (p != nullptr)
{
assert(p == Alloc::external_pointer<Start>(p));
size_t sz =
(std::min)(size, SNMALLOC_NAME_MANGLE(malloc_usable_size)(ptr));
sz = (std::min)(size, sz);
memcpy(p, ptr, sz);
SNMALLOC_NAME_MANGLE(free)(ptr);
}
Expand Down