From 3e414ec314690aac0d8b71f27f8681c8e4a90d50 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 28 Mar 2007 22:53:45 +0000 Subject: [PATCH] Fixed broken iteration in block_cache::RemoveUnusedBlocks(). The loop would start with the first block in the unused blocks list, but then continue with the blocks that share the same hash table slot, thus freeing potentially used blocks. Could theoretically have caused BFS to see and write incorrect meta/administrative data on certain occasions. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20459 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/cache/block_cache.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/system/kernel/cache/block_cache.cpp b/src/system/kernel/cache/block_cache.cpp index 6b14e5ff54..94fa4904bf 100644 --- a/src/system/kernel/cache/block_cache.cpp +++ b/src/system/kernel/cache/block_cache.cpp @@ -339,10 +339,8 @@ block_cache::RemoveUnusedBlocks(int32 maxAccessed, int32 count) { TRACE(("block_cache: remove up to %ld unused blocks\n", count)); - cached_block *next = NULL; - for (cached_block *block = unused_blocks.First(); block != NULL; - block = next) { - next = block->next; + for (block_list::Iterator it = unused_blocks.GetIterator(); + cached_block *block = it.Next();) { if (maxAccessed < block->accessed) continue; @@ -355,7 +353,7 @@ block_cache::RemoveUnusedBlocks(int32 maxAccessed, int32 count) write_cached_block(this, block, false); // remove block from lists - unused_blocks.Remove(block); + it.Remove(); hash_remove(hash, block); FreeBlock(block);