From c832ff1e1b3505722e6a6e755cee3b2e51368c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 4 May 2004 00:07:38 +0000 Subject: [PATCH] Fixed a race condition in the block allocator initialization (the lock was held too late, and could theoretically already be acquired by someone else). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7402 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp index a0f17b5f6e..b7297593f4 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp @@ -342,6 +342,9 @@ BlockAllocator::Initialize(bool full) if (!full) return B_OK; + fLock.Lock(); + // the lock will be released by the initialize() function + thread_id id = spawn_kernel_thread((thread_func)BlockAllocator::initialize, "bfs block allocator", B_LOW_PRIORITY, (void *)this); if (id < B_OK) @@ -401,7 +404,7 @@ BlockAllocator::InitializeAndClearBitmap(Transaction &transaction) status_t BlockAllocator::initialize(BlockAllocator *allocator) { - Locker lock(allocator->fLock); + // The lock must already be held at this point! Volume *volume = allocator->fVolume; uint32 blocks = allocator->fBlocksPerGroup; @@ -409,8 +412,10 @@ BlockAllocator::initialize(BlockAllocator *allocator) off_t freeBlocks = 0; uint32 *buffer = (uint32 *)malloc(numBits >> 3); - if (buffer == NULL) + if (buffer == NULL) { + allocator->fLock.Unlock(); RETURN_ERROR(B_NO_MEMORY); + } AllocationGroup *groups = allocator->fGroups; off_t offset = 1; @@ -470,6 +475,7 @@ BlockAllocator::initialize(BlockAllocator *allocator) volume->SuperBlock().used_blocks = HOST_ENDIAN_TO_BFS_INT64(usedBlocks); } + allocator->fLock.Unlock(); return B_OK; }