mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
attempt to fix the crash at exit, due to some threads asking for memory while the memory management structure is already gone
This commit is contained in:
parent
22fd4e4092
commit
e56ba457fe
@ -158,6 +158,13 @@ void FixedAllocator::deallocate(void *p)
|
||||
_chunks.pop_back();
|
||||
}
|
||||
}
|
||||
uint32_t FixedAllocator::currentSize() const
|
||||
{
|
||||
uint32_t res = 0 ;
|
||||
|
||||
for(uint32_t i=0;i<_chunks.size();++i)
|
||||
res += (_numBlocks - _chunks[i]->_blocksAvailable) * _blockSize ;
|
||||
}
|
||||
void FixedAllocator::printStatistics() const
|
||||
{
|
||||
std::cerr << " numBLocks=" << (int)_numBlocks << std::endl;
|
||||
@ -181,10 +188,17 @@ SmallObjectAllocator::~SmallObjectAllocator()
|
||||
{
|
||||
RsStackMutex m(SmallObject::_mtx) ;
|
||||
|
||||
for(std::map<int,FixedAllocator*>::const_iterator it(_pool.begin());it!=_pool.end();++it)
|
||||
delete it->second ;
|
||||
//std::cerr << __PRETTY_FUNCTION__ << " not deleting. Leaving it to the system." << std::endl;
|
||||
|
||||
_active = false ;
|
||||
|
||||
uint32_t still_allocated = 0 ;
|
||||
|
||||
for(std::map<int,FixedAllocator*>::const_iterator it(_pool.begin());it!=_pool.end();++it)
|
||||
still_allocated += it->second->currentSize() ;
|
||||
//delete it->second ;
|
||||
|
||||
std::cerr << "Memory still in use at end of program: " << still_allocated << " bytes." << std::endl;
|
||||
}
|
||||
|
||||
void *SmallObjectAllocator::allocate(size_t bytes)
|
||||
|
@ -68,8 +68,9 @@ namespace RsMemoryManagement
|
||||
return p >= c._data && (static_cast<unsigned char *>(p)-c._data)/_blockSize < _numBlocks ;
|
||||
}
|
||||
|
||||
void printStatistics() const ;
|
||||
private:
|
||||
void printStatistics() const ;
|
||||
uint32_t currentSize() const;
|
||||
private:
|
||||
size_t _blockSize ;
|
||||
unsigned char _numBlocks ;
|
||||
std::vector<Chunk*> _chunks ;
|
||||
|
Loading…
Reference in New Issue
Block a user