mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-17 21:34:10 -05: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();
|
_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
|
void FixedAllocator::printStatistics() const
|
||||||
{
|
{
|
||||||
std::cerr << " numBLocks=" << (int)_numBlocks << std::endl;
|
std::cerr << " numBLocks=" << (int)_numBlocks << std::endl;
|
||||||
@ -181,10 +188,17 @@ SmallObjectAllocator::~SmallObjectAllocator()
|
|||||||
{
|
{
|
||||||
RsStackMutex m(SmallObject::_mtx) ;
|
RsStackMutex m(SmallObject::_mtx) ;
|
||||||
|
|
||||||
for(std::map<int,FixedAllocator*>::const_iterator it(_pool.begin());it!=_pool.end();++it)
|
//std::cerr << __PRETTY_FUNCTION__ << " not deleting. Leaving it to the system." << std::endl;
|
||||||
delete it->second ;
|
|
||||||
|
|
||||||
_active = false ;
|
_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)
|
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 ;
|
return p >= c._data && (static_cast<unsigned char *>(p)-c._data)/_blockSize < _numBlocks ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printStatistics() const ;
|
void printStatistics() const ;
|
||||||
private:
|
uint32_t currentSize() const;
|
||||||
|
private:
|
||||||
size_t _blockSize ;
|
size_t _blockSize ;
|
||||||
unsigned char _numBlocks ;
|
unsigned char _numBlocks ;
|
||||||
std::vector<Chunk*> _chunks ;
|
std::vector<Chunk*> _chunks ;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user