Skip to content

Commit 88a2740

Browse files
authored
Add stricter double free checking on large allocs (#550)
Although, double frees are generally caught on large allocs. This is done very late in the process after many operations more operations have occurred. This change brings that check much earlier in the process.
1 parent f8efcb7 commit 88a2740

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/snmalloc/mem/localalloc.h

+6
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ namespace snmalloc
629629

630630
const PagemapEntry& entry =
631631
Config::Backend::get_metaentry(address_cast(p_tame));
632+
632633
if (SNMALLOC_LIKELY(local_cache.remote_allocator == entry.get_remote()))
633634
{
634635
# if defined(__CHERI_PURE_CAPABILITY__) && defined(SNMALLOC_CHECK_CLIENT)
@@ -647,6 +648,11 @@ namespace snmalloc
647648
# if defined(__CHERI_PURE_CAPABILITY__) && defined(SNMALLOC_CHECK_CLIENT)
648649
dealloc_cheri_checks(p_tame.unsafe_ptr());
649650
# endif
651+
652+
// Detect double free of large allocations here.
653+
snmalloc_check_client(
654+
!entry.is_backend_owned(), "Memory corruption detected");
655+
650656
// Check if we have space for the remote deallocation
651657
if (local_cache.remote_dealloc_cache.reserve_space(entry))
652658
{

0 commit comments

Comments
 (0)