From f5f2076db53ed436e67b210127b5596fcf34ac44 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Fri, 14 Oct 2022 01:07:37 -0700 Subject: [PATCH] [kernel] Lock the heap allocator for part of reallocate heap_allocator::reallocate relies on the allocate and free methods so mostly doesn't need locking, but it does touch the tracking map, so needs to protect that with a lock. --- src/kernel/heap_allocator.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/kernel/heap_allocator.cpp b/src/kernel/heap_allocator.cpp index cff726f..ea62536 100644 --- a/src/kernel/heap_allocator.cpp +++ b/src/kernel/heap_allocator.cpp @@ -111,6 +111,8 @@ heap_allocator::reallocate(void *p, size_t old_length, size_t new_length) return allocate(new_length); } + util::scoped_lock lock {m_lock}; + block_info *info = m_map.find(map_key(p)); kassert(info, "Attempt to reallocate unknown block"); if (!info) @@ -119,6 +121,7 @@ heap_allocator::reallocate(void *p, size_t old_length, size_t new_length) if (new_length <= (1 << info->order)) return p; + lock.release(); void *new_block = allocate(new_length); memcpy(new_block, p, old_length); free(p);