From 57a9a439a1fa94bc6c1d59230eae3a5360ff8272 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 1 Feb 2015 10:51:51 +0000 Subject: fix for major handle leak git-svn-id: http://svn.miranda-ng.org/main/trunk@11972 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/WhatsApp/src/connection.cpp | 2 +- protocols/WhatsApp/src/utils.h | 45 +++++++---------------------------- 2 files changed, 9 insertions(+), 38 deletions(-) (limited to 'protocols/WhatsApp') diff --git a/protocols/WhatsApp/src/connection.cpp b/protocols/WhatsApp/src/connection.cpp index 1eb90cd8ed..c0710e626e 100644 --- a/protocols/WhatsApp/src/connection.cpp +++ b/protocols/WhatsApp/src/connection.cpp @@ -136,7 +136,7 @@ void WhatsAppProto::sentinelLoop(void*) void WhatsAppProto::onPing(const std::string& id) { - if (this->isOnline()) { + if (isOnline()) { try { debugLogA("Sending pong with id %s", id.c_str()); m_pConnection->sendPong(id); diff --git a/protocols/WhatsApp/src/utils.h b/protocols/WhatsApp/src/utils.h index 7f0d903d1b..a14a707a14 100644 --- a/protocols/WhatsApp/src/utils.h +++ b/protocols/WhatsApp/src/utils.h @@ -3,53 +3,24 @@ #include "WhatsAPI++/IMutex.h" -class ScopedLock -{ -public: - ScopedLock(HANDLE h, int t = INFINITE) : handle_(h), timeout_(t) - { - WaitForSingleObject(handle_, timeout_); - } - ~ScopedLock() - { - if (handle_) - ReleaseMutex(handle_); - } - void Unlock() - { - ReleaseMutex(handle_); - handle_ = 0; - } -private: - HANDLE handle_; - int timeout_; -}; - class Mutex : public IMutex { -private: - HANDLE handle; -public: - Mutex() : handle(NULL) {} + mir_cs m_cs; - virtual ~Mutex() - { - if (this->handle != NULL) { - ReleaseMutex(this->handle); - } - } +public: + Mutex() {} + virtual ~Mutex() {} virtual void lock() { - if (this->handle == NULL) { - this->handle = CreateMutex(NULL, FALSE, NULL); - } + CRITICAL_SECTION &cs = m_cs; + ::EnterCriticalSection(&cs); } virtual void unlock() { - ReleaseMutex(this->handle); - this->handle = NULL; + CRITICAL_SECTION &cs = m_cs; + ::LeaveCriticalSection(&cs); } }; -- cgit v1.2.3