[haiku-commits] r35918 - haiku/trunk/src/system/kernel/cache

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 19 Mar 2010 20:07:19 +0100 (CET)

Author: bonefish
Date: 2010-03-19 20:07:18 +0100 (Fri, 19 Mar 2010)
New Revision: 35918
Changeset: http://dev.haiku-os.org/changeset/35918/haiku

Modified:
   haiku/trunk/src/system/kernel/cache/block_cache.cpp
Log:
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.


Modified: haiku/trunk/src/system/kernel/cache/block_cache.cpp
===================================================================
--- haiku/trunk/src/system/kernel/cache/block_cache.cpp 2010-03-19 18:27:28 UTC 
(rev 35917)
+++ haiku/trunk/src/system/kernel/cache/block_cache.cpp 2010-03-19 19:07:18 UTC 
(rev 35918)
@@ -1412,7 +1412,13 @@
        }
        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->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;


Other related posts:

  • » [haiku-commits] r35918 - haiku/trunk/src/system/kernel/cache - ingo_weinhold