aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-03-29 23:53:42 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-03-29 23:53:42 -0700
commita536d04f543ca0b8a2f3bc9ec28f3424b390355a (patch)
treef5f935e6e83e77a4aa0006157ef2c8a883602d4a
parent7d80e3d568554f0c742a41bb9c9af567d71b5b83 (diff)
Fixed dispatch queue memory management.
-rwxr-xr-xsrc/async/imap/MCIMAPAsyncSession.cc11
-rw-r--r--src/core/basetypes/MCOperation.cc11
-rw-r--r--src/core/basetypes/MCOperationQueue.cc11
-rwxr-xr-xsrc/objc/imap/MCOIMAPSession.h2
-rw-r--r--src/objc/pop/MCOPOPSession.h2
-rw-r--r--src/objc/smtp/MCOSMTPSession.h2
-rw-r--r--src/objc/utils/MCOOperation.h2
7 files changed, 37 insertions, 4 deletions
diff --git a/src/async/imap/MCIMAPAsyncSession.cc b/src/async/imap/MCIMAPAsyncSession.cc
index c037768f..e94b62fe 100755
--- a/src/async/imap/MCIMAPAsyncSession.cc
+++ b/src/async/imap/MCIMAPAsyncSession.cc
@@ -50,6 +50,11 @@ IMAPAsyncSession::IMAPAsyncSession()
IMAPAsyncSession::~IMAPAsyncSession()
{
+#if __APPLE__
+ if (mDispatchQueue != NULL) {
+ dispatch_release(mDispatchQueue);
+ }
+#endif
MC_SAFE_RELEASE(mGmailUserDisplayName);
MC_SAFE_RELEASE(mServerIdentity);
MC_SAFE_RELEASE(mClientIdentity);
@@ -602,7 +607,13 @@ void IMAPAsyncSession::operationRunningStateChanged()
#if __APPLE__
void IMAPAsyncSession::setDispatchQueue(dispatch_queue_t dispatchQueue)
{
+ if (mDispatchQueue != NULL) {
+ dispatch_release(mDispatchQueue);
+ }
mDispatchQueue = dispatchQueue;
+ if (mDispatchQueue != NULL) {
+ dispatch_retain(mDispatchQueue);
+ }
}
dispatch_queue_t IMAPAsyncSession::dispatchQueue()
diff --git a/src/core/basetypes/MCOperation.cc b/src/core/basetypes/MCOperation.cc
index 71b3c52f..51497cba 100644
--- a/src/core/basetypes/MCOperation.cc
+++ b/src/core/basetypes/MCOperation.cc
@@ -15,6 +15,11 @@ Operation::Operation()
Operation::~Operation()
{
+#if __APPLE__
+ if (mCallbackDispatchQueue != NULL) {
+ dispatch_release(mCallbackDispatchQueue);
+ }
+#endif
pthread_mutex_destroy(&mLock);
}
@@ -73,7 +78,13 @@ void Operation::start()
#if __APPLE__
void Operation::setCallbackDispatchQueue(dispatch_queue_t callbackDispatchQueue)
{
+ if (mCallbackDispatchQueue != NULL) {
+ dispatch_release(mCallbackDispatchQueue);
+ }
mCallbackDispatchQueue = callbackDispatchQueue;
+ if (mCallbackDispatchQueue != NULL) {
+ dispatch_retain(mCallbackDispatchQueue);
+ }
}
dispatch_queue_t Operation::callbackDispatchQueue()
diff --git a/src/core/basetypes/MCOperationQueue.cc b/src/core/basetypes/MCOperationQueue.cc
index 3619530b..9a740ef6 100644
--- a/src/core/basetypes/MCOperationQueue.cc
+++ b/src/core/basetypes/MCOperationQueue.cc
@@ -32,6 +32,11 @@ OperationQueue::OperationQueue()
OperationQueue::~OperationQueue()
{
+#if __APPLE__
+ if (mDispatchQueue != NULL) {
+ dispatch_release(mDispatchQueue);
+ }
+#endif
MC_SAFE_RELEASE(mOperations);
pthread_mutex_destroy(&mLock);
mailsem_free(mOperationSem);
@@ -266,7 +271,13 @@ void OperationQueue::waitUntilAllOperationsAreFinished()
#if __APPLE__
void OperationQueue::setDispatchQueue(dispatch_queue_t dispatchQueue)
{
+ if (mDispatchQueue != NULL) {
+ dispatch_release(mDispatchQueue);
+ }
mDispatchQueue = dispatchQueue;
+ if (mDispatchQueue != NULL) {
+ dispatch_retain(mDispatchQueue);
+ }
}
dispatch_queue_t OperationQueue::dispatchQueue()
diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h
index 09f1c610..101f7953 100755
--- a/src/objc/imap/MCOIMAPSession.h
+++ b/src/objc/imap/MCOIMAPSession.h
@@ -117,7 +117,7 @@
It will make MCOIMAPSession safe. It will also set all the callbacks of operations to run on this given queue.
Defaults to the main queue.
This property should be used only if there's performance issue using MCOIMAPSession in the main thread. */
-@property (nonatomic, assign) dispatch_queue_t dispatchQueue;
+@property (nonatomic, retain) dispatch_queue_t dispatchQueue;
/**
The value will be YES when asynchronous operations are running, else it will return NO.
diff --git a/src/objc/pop/MCOPOPSession.h b/src/objc/pop/MCOPOPSession.h
index ebfa5ad2..74ed216b 100644
--- a/src/objc/pop/MCOPOPSession.h
+++ b/src/objc/pop/MCOPOPSession.h
@@ -66,7 +66,7 @@ See MCOConnectionType for more information.*/
It will make MCOPOPSession safe. It will also set all the callbacks of operations to run on this given queue.
Defaults to the main queue.
This property should be used only if there's performance issue using MCOPOPSession in the main thread. */
-@property (nonatomic, assign) dispatch_queue_t dispatchQueue;
+@property (nonatomic, retain) dispatch_queue_t dispatchQueue;
/** @name Operations */
diff --git a/src/objc/smtp/MCOSMTPSession.h b/src/objc/smtp/MCOSMTPSession.h
index 6233e2bb..8e5deaa3 100644
--- a/src/objc/smtp/MCOSMTPSession.h
+++ b/src/objc/smtp/MCOSMTPSession.h
@@ -80,7 +80,7 @@
It will make MCOSMTPSession safe. It will also set all the callbacks of operations to run on this given queue.
Defaults to the main queue.
This property should be used only if there's performance issue using MCOSMTPSession in the main thread. */
-@property (nonatomic, assign) dispatch_queue_t dispatchQueue;
+@property (nonatomic, retain) dispatch_queue_t dispatchQueue;
/** @name Operations */
diff --git a/src/objc/utils/MCOOperation.h b/src/objc/utils/MCOOperation.h
index f46536c9..b42dfbef 100644
--- a/src/objc/utils/MCOOperation.h
+++ b/src/objc/utils/MCOOperation.h
@@ -23,7 +23,7 @@
/** The queue this operation dispatches the callback on. Defaults to the main queue.
This property should be used only if there's performance issue creating or calling the callback
in the main thread. */
-@property (nonatomic, assign) dispatch_queue_t callbackDispatchQueue;
+@property (nonatomic, retain) dispatch_queue_t callbackDispatchQueue;
/** This methods is called on the main thread when the asynchronous operation is finished.
Needs to be overriden by subclasses.*/