From 92aa90cc6ff2711eba605deacd905412949f48a9 Mon Sep 17 00:00:00 2001 From: rich_sposato Date: Wed, 8 Sep 2010 02:22:28 +0000 Subject: [PATCH] Fixed bug 3061653 by adding code to check pointers to chunks before searching. Fixed bug 3061659 by checking for empty list. git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@1073 7ec92016-0320-0410-acc4-a06ded1c099a --- src/SmallObj.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/SmallObj.cpp b/src/SmallObj.cpp index c04c76b..89da338 100644 --- a/src/SmallObj.cpp +++ b/src/SmallObj.cpp @@ -821,10 +821,23 @@ bool FixedAllocator::TrimChunkList( void ) if ( chunks_.size() == chunks_.capacity() ) return false; - // Use the "make-a-temp-and-swap" trick to remove excess capacity. - Chunks( chunks_ ).swap( chunks_ ); - deallocChunk_ = &chunks_.front(); - allocChunk_ = &chunks_.back(); + + { + // Use the "make-a-temp-and-swap" trick to remove excess capacity. + Chunks temp( chunks_ ); + temp.swap( chunks_ ); + } + + if ( chunks_.empty() ) + { + deallocChunk_ = nullptr; + allocChunk_ = nullptr; + } + else + { + deallocChunk_ = &chunks_.front(); + allocChunk_ = &chunks_.back(); + } return true; } @@ -929,7 +942,15 @@ bool FixedAllocator::Deallocate( void * p, Chunk * hint ) assert( &chunks_.back() >= allocChunk_ ); assert( CountEmptyChunks() < 2 ); - Chunk * foundChunk = ( nullptr == hint ) ? VicinityFind( p ) : hint; + Chunk * foundChunk = nullptr; + if ( ( nullptr != hint ) && ( hint->HasBlock( p, numBlocks_ * blockSize_ ) ) ) + foundChunk = hint; + else if ( deallocChunk_->HasBlock( p, numBlocks_ * blockSize_ ) ) + foundChunk = deallocChunk_; + else if ( allocChunk_->HasBlock( p, numBlocks_ * blockSize_ ) ) + foundChunk = allocChunk_; + else + foundChunk = VicinityFind( p ); if ( nullptr == foundChunk ) return false;