From c561bf792b15cfa12f5166c0094d1c0d62d53f90 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 19 Mar 2010 19:07:18 +0000 Subject: [PATCH] block_cache::NewBlock(): Allocate cached_block::current_data only when the block was freshly allocated. A block returned by _GetUnusedBlock() already has current_data and we would leak it before. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35918 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/cache/block_cache.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/system/kernel/cache/block_cache.cpp b/src/system/kernel/cache/block_cache.cpp index 131ff54417..a1fd59cfab 100644 --- a/src/system/kernel/cache/block_cache.cpp +++ b/src/system/kernel/cache/block_cache.cpp @@ -1412,7 +1412,13 @@ block_cache::NewBlock(off_t blockNumber) } if (block == NULL) { block = (cached_block*)object_cache_alloc(sBlockCache, 0); - if (block == NULL) { + if (block != NULL) { + block->current_data = Allocate(); + if (block->current_data == NULL) { + object_cache_free(sBlockCache, block, 0); + return NULL; + } + } else { TB(Error(this, blockNumber, "allocation failed")); dprintf("block allocation failed, unused list is %sempty.\n", unused_blocks.IsEmpty() ? "" : "not "); @@ -1427,12 +1433,6 @@ block_cache::NewBlock(off_t blockNumber) } } - block->current_data = Allocate(); - if (block->current_data == NULL) { - object_cache_free(sBlockCache, block, 0); - return NULL; - } - block->block_number = blockNumber; block->ref_count = 0; block->last_accessed = 0;