aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-07-20 20:27:40 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-07-20 20:27:40 -0700
commitd97a11e8f445422d1fcf83cca2ebe9c29e6b827f (patch)
treedebea170bb173e8619793e7fcc25c3c4bcf8b9ca
parent63086bddce5d12b72f5d035fdb0b2ae52854b477 (diff)
Fixed memory leak (fixed #794)
-rw-r--r--src/core/basetypes/MCOperationQueue.cc12
-rw-r--r--src/core/basetypes/MCOperationQueue.h1
2 files changed, 11 insertions, 2 deletions
diff --git a/src/core/basetypes/MCOperationQueue.cc b/src/core/basetypes/MCOperationQueue.cc
index 9a740ef6..e45f04ee 100644
--- a/src/core/basetypes/MCOperationQueue.cc
+++ b/src/core/basetypes/MCOperationQueue.cc
@@ -28,6 +28,7 @@ OperationQueue::OperationQueue()
#if __APPLE__
mDispatchQueue = dispatch_get_main_queue();
#endif
+ _pendingCheckRunning = false;
}
OperationQueue::~OperationQueue()
@@ -175,12 +176,19 @@ void OperationQueue::callbackOnMainThread(Operation * op)
void OperationQueue::checkRunningOnMainThread(void * context)
{
- cancelDelayedPerformMethod((Object::Method) &OperationQueue::checkRunningAfterDelay, NULL);
+ retain(); // (4)
+ if (_pendingCheckRunning) {
+ cancelDelayedPerformMethod((Object::Method) &OperationQueue::checkRunningAfterDelay, NULL);
+ release(); // (4)
+ }
+ _pendingCheckRunning = true;
performMethodAfterDelay((Object::Method) &OperationQueue::checkRunningAfterDelay, NULL, 1);
+ release(); // (1)
}
void OperationQueue::checkRunningAfterDelay(void * context)
{
+ _pendingCheckRunning = false;
pthread_mutex_lock(&mLock);
if (!mQuitting) {
if (mOperations->count() == 0) {
@@ -194,7 +202,7 @@ void OperationQueue::checkRunningAfterDelay(void * context)
// Number of operations can't be changed because it runs on main thread.
// And addOperation() should also be called from main thread.
- release(); // (1)
+ release(); // (4)
}
void OperationQueue::stoppedOnMainThread(void * context)
diff --git a/src/core/basetypes/MCOperationQueue.h b/src/core/basetypes/MCOperationQueue.h
index b5f29143..119befcc 100644
--- a/src/core/basetypes/MCOperationQueue.h
+++ b/src/core/basetypes/MCOperationQueue.h
@@ -48,6 +48,7 @@ namespace mailcore {
#if __APPLE__
dispatch_queue_t mDispatchQueue;
#endif
+ bool _pendingCheckRunning;
void startThread();
static void runOperationsOnThread(OperationQueue * queue);