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
This commit is contained in:
parent
edac001bf0
commit
92aa90cc6f
1 changed files with 26 additions and 5 deletions
|
@ -821,10 +821,23 @@ bool FixedAllocator::TrimChunkList( void )
|
||||||
|
|
||||||
if ( chunks_.size() == chunks_.capacity() )
|
if ( chunks_.size() == chunks_.capacity() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
{
|
||||||
// Use the "make-a-temp-and-swap" trick to remove excess capacity.
|
// Use the "make-a-temp-and-swap" trick to remove excess capacity.
|
||||||
Chunks( chunks_ ).swap( chunks_ );
|
Chunks temp( chunks_ );
|
||||||
|
temp.swap( chunks_ );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( chunks_.empty() )
|
||||||
|
{
|
||||||
|
deallocChunk_ = nullptr;
|
||||||
|
allocChunk_ = nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
deallocChunk_ = &chunks_.front();
|
deallocChunk_ = &chunks_.front();
|
||||||
allocChunk_ = &chunks_.back();
|
allocChunk_ = &chunks_.back();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -929,7 +942,15 @@ bool FixedAllocator::Deallocate( void * p, Chunk * hint )
|
||||||
assert( &chunks_.back() >= allocChunk_ );
|
assert( &chunks_.back() >= allocChunk_ );
|
||||||
assert( CountEmptyChunks() < 2 );
|
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 )
|
if ( nullptr == foundChunk )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue