Fix many memory leaks
This commit is contained in:
@@ -28,63 +28,47 @@ static volatile int64 totalNodeConstruct = 0;
|
||||
static volatile int64 totalNodeDestruct = 0;
|
||||
static volatile int64 totalTimerConstruct = 0;
|
||||
static volatile int64 totalTimerDestruct = 0;
|
||||
static Mutex *globalMutex = 0;
|
||||
static Mutex globalMutex;
|
||||
static bool notInited = true;
|
||||
|
||||
static int64 getTotalTimerNodeConstruct()
|
||||
{
|
||||
Lock xx(globalMutex);
|
||||
Lock xx(&globalMutex);
|
||||
return totalNodeConstruct;
|
||||
}
|
||||
|
||||
static int64 getTotalTimerNodeDestruct()
|
||||
{
|
||||
Lock xx(globalMutex);
|
||||
Lock xx(&globalMutex);
|
||||
return totalNodeDestruct;
|
||||
}
|
||||
|
||||
static int64 getTotalTimerConstruct()
|
||||
{
|
||||
Lock xx(globalMutex);
|
||||
Lock xx(&globalMutex);
|
||||
return totalTimerConstruct;
|
||||
}
|
||||
|
||||
static int64 getTotalTimerDestruct()
|
||||
{
|
||||
Lock xx(globalMutex);
|
||||
Lock xx(&globalMutex);
|
||||
return totalTimerDestruct;
|
||||
}
|
||||
|
||||
static ConstructDestructCallback *pCDCallbackTimerNode;
|
||||
static ConstructDestructCallback *pCDCallbackTimer;
|
||||
|
||||
static void init()
|
||||
{
|
||||
static Mutex mutex = Mutex();
|
||||
Lock xx(&mutex);
|
||||
if(globalMutex==0) {
|
||||
globalMutex = new Mutex();
|
||||
pCDCallbackTimerNode = new ConstructDestructCallback(
|
||||
Lock xx(&globalMutex);
|
||||
if(notInited) {
|
||||
notInited = false;
|
||||
ShowConstructDestruct::registerCallback(
|
||||
"timerNode",
|
||||
getTotalTimerNodeConstruct,getTotalTimerNodeDestruct,0);
|
||||
|
||||
pCDCallbackTimer = new ConstructDestructCallback(
|
||||
getTotalTimerNodeConstruct,getTotalTimerNodeDestruct,0,0);
|
||||
ShowConstructDestruct::registerCallback(
|
||||
"timer",
|
||||
getTotalTimerConstruct,getTotalTimerDestruct,0);
|
||||
getTotalTimerConstruct,getTotalTimerDestruct,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
ConstructDestructCallback * TimerNode::getConstructDestructCallback()
|
||||
{
|
||||
init();
|
||||
return pCDCallbackTimerNode;
|
||||
}
|
||||
|
||||
ConstructDestructCallback * Timer::getConstructDestructCallback()
|
||||
{
|
||||
init();
|
||||
return pCDCallbackTimer;
|
||||
}
|
||||
|
||||
class TimerNodePvt;
|
||||
|
||||
typedef LinkedListNode<TimerNodePvt> TimerListNode;
|
||||
@@ -171,7 +155,7 @@ TimerNode::TimerNode(TimerCallback *callback)
|
||||
: pImpl(new TimerNodePvt(this,callback))
|
||||
{
|
||||
init();
|
||||
Lock xx(globalMutex);
|
||||
Lock xx(&globalMutex);
|
||||
totalNodeConstruct++;
|
||||
}
|
||||
|
||||
@@ -180,7 +164,7 @@ TimerNode::~TimerNode()
|
||||
{
|
||||
cancel();
|
||||
delete pImpl;
|
||||
Lock xx(globalMutex);
|
||||
Lock xx(&globalMutex);
|
||||
totalNodeDestruct++;
|
||||
}
|
||||
|
||||
@@ -257,7 +241,7 @@ Timer::Timer(String threadName, ThreadPriority priority)
|
||||
: pImpl(new TimerPvt(threadName,priority))
|
||||
{
|
||||
init();
|
||||
Lock xx(globalMutex);
|
||||
Lock xx(&globalMutex);
|
||||
totalTimerConstruct++;
|
||||
}
|
||||
|
||||
@@ -274,7 +258,7 @@ Timer::~Timer() {
|
||||
node->getObject()->callback->timerStopped();
|
||||
}
|
||||
delete pImpl;
|
||||
Lock xx(globalMutex);
|
||||
Lock xx(&globalMutex);
|
||||
totalTimerDestruct++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user