summaryrefslogtreecommitdiffstats
path: root/libsysutils/src/SocketClient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libsysutils/src/SocketClient.cpp')
-rw-r--r--libsysutils/src/SocketClient.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp
index 6d4dff45d..90ca52e74 100644
--- a/libsysutils/src/SocketClient.cpp
+++ b/libsysutils/src/SocketClient.cpp
@@ -104,20 +104,23 @@ int SocketClient::sendData(const void* data, int len) {
}
void SocketClient::incRef() {
- pthread_mutex_lock(&mRefCountMutex);
- mRefCount++;
- pthread_mutex_unlock(&mRefCountMutex);
+ pthread_mutex_lock(&mRefCountMutex);
+ mRefCount++;
+ pthread_mutex_unlock(&mRefCountMutex);
}
-void SocketClient::decRef() {
- bool deleteSelf = false;
- pthread_mutex_lock(&mRefCountMutex);
- mRefCount--;
- if (mRefCount == 0) {
- deleteSelf = true;
- }
- pthread_mutex_unlock(&mRefCountMutex);
- if (deleteSelf) {
- delete this;
- }
+bool SocketClient::decRef() {
+ bool deleteSelf = false;
+ pthread_mutex_lock(&mRefCountMutex);
+ mRefCount--;
+ if (mRefCount == 0) {
+ deleteSelf = true;
+ } else if (mRefCount < 0) {
+ SLOGE("SocketClient refcount went negative!");
+ }
+ pthread_mutex_unlock(&mRefCountMutex);
+ if (deleteSelf) {
+ delete this;
+ }
+ return deleteSelf;
}