suppressed potential SIGSEGV as exit time

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4068 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-03-02 14:33:32 +00:00
parent 3ae378d9b9
commit 800cc281c5
2 changed files with 23 additions and 0 deletions

View File

@ -170,14 +170,21 @@ void FixedAllocator::printStatistics() const
SmallObjectAllocator::SmallObjectAllocator(size_t maxObjectSize)
: _maxObjectSize(maxObjectSize)
{
RsStackMutex m(SmallObject::_mtx) ;
_lastAlloc = NULL ;
_lastDealloc = NULL ;
_active = true ;
}
SmallObjectAllocator::~SmallObjectAllocator()
{
RsStackMutex m(SmallObject::_mtx) ;
for(std::map<int,FixedAllocator*>::const_iterator it(_pool.begin());it!=_pool.end();++it)
delete it->second ;
_active = false ;
}
void *SmallObjectAllocator::allocate(size_t bytes)
@ -255,6 +262,10 @@ void *SmallObject::operator new(size_t size)
#endif
RsStackMutex m(_mtx) ;
if(!_allocator._active)
return (void*)NULL;
void *p = _allocator.allocate(size) ;
#ifdef DEBUG_MEMORY
std::cerr << "new RsItem: " << p << ", size=" << size << std::endl;
@ -265,6 +276,10 @@ void *SmallObject::operator new(size_t size)
void SmallObject::operator delete(void *p,size_t size)
{
RsStackMutex m(_mtx) ;
if(!_allocator._active)
return ;
_allocator.deallocate(p,size) ;
#ifdef DEBUG_MEMORY
std::cerr << "del RsItem: " << p << ", size=" << size << std::endl;
@ -274,6 +289,10 @@ void SmallObject::operator delete(void *p,size_t size)
void SmallObject::printStatistics()
{
RsStackMutex m(_mtx) ;
if(!_allocator._active)
return ;
_allocator.printStatistics() ;
}

View File

@ -85,6 +85,8 @@ namespace RsMemoryManagement
void deallocate(void *p,size_t size) ;
void printStatistics() const ;
bool _active ;
private:
std::map<int,FixedAllocator*> _pool ;
FixedAllocator *_lastAlloc ;
@ -105,6 +107,8 @@ namespace RsMemoryManagement
private:
static SmallObjectAllocator _allocator ;
static RsMutex _mtx;
friend class SmallObjectAllocator ;
};
extern void printStatistics() ;