summaryrefslogtreecommitdiff
path: root/protocols/VKontakte/src
diff options
context:
space:
mode:
authorElzorFox <elzorfox@ya.ru>2018-12-31 15:07:02 +0500
committerElzorFox <elzorfox@ya.ru>2018-12-31 15:07:02 +0500
commit7846d1b5524ad17e9e8562ee6cf2f893b985089f (patch)
tree8af0be8c8b8d3f0823253466425803bc1d453483 /protocols/VKontakte/src
parent8b58336ffa5a55ac8576548ebb3e4c1f68d9977c (diff)
VKontakte: fix socket leak
Diffstat (limited to 'protocols/VKontakte/src')
-rw-r--r--protocols/VKontakte/src/vk_pollserver.cpp12
-rw-r--r--protocols/VKontakte/src/vk_proto.h2
-rw-r--r--protocols/VKontakte/src/vk_queue.cpp11
-rw-r--r--protocols/VKontakte/src/vk_thread.cpp21
4 files changed, 27 insertions, 19 deletions
diff --git a/protocols/VKontakte/src/vk_pollserver.cpp b/protocols/VKontakte/src/vk_pollserver.cpp
index 5fa6554b0f..6ccbeb039c 100644
--- a/protocols/VKontakte/src/vk_pollserver.cpp
+++ b/protocols/VKontakte/src/vk_pollserver.cpp
@@ -39,7 +39,7 @@ void CVkProto::OnReceivePollingInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *
if (!jnResponse) {
if (!pReq->bNeedsRestart) {
debugLogA("CVkProto::OnReceivePollingInfo PollingThread not start (getLongPollServer error)");
- m_pollingConn = nullptr;
+ ClosePollingConnection();
ShutdownSession();
}
return;
@@ -64,7 +64,7 @@ void CVkProto::OnReceivePollingInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *
}
else {
debugLogA("CVkProto::OnReceivePollingInfo PollingThread not start");
- m_pollingConn = nullptr;
+ ClosePollingConnection();
ShutdownSession();
return;
}
@@ -242,7 +242,7 @@ int CVkProto::PollServer()
debugLogA("CVkProto::PollServer");
if (!IsOnline()) {
debugLogA("CVkProto::PollServer is dead (not online)");
- m_pollingConn = nullptr;
+ ClosePollingConnection();
ShutdownSession();
return 0;
}
@@ -262,7 +262,7 @@ int CVkProto::PollServer()
while ((reply = Netlib_HttpTransaction(m_hNetlibUser, &req)) == nullptr) {
debugLogA("CVkProto::PollServer is dead");
- m_pollingConn = nullptr;
+ ClosePollingConnection();
if (iPollConnRetry && !m_bTerminated) {
iPollConnRetry--;
debugLogA("CVkProto::PollServer restarting %d", MAX_RETRIES - iPollConnRetry);
@@ -297,7 +297,7 @@ int CVkProto::PollServer()
else if ((reply->resultCode >= 400 && reply->resultCode <= 417)
|| (reply->resultCode >= 500 && reply->resultCode <= 509)) {
debugLogA("CVkProto::PollServer is dead. Error code - %d", reply->resultCode);
- m_pollingConn = nullptr;
+ ClosePollingConnection();
Netlib_FreeHttpRequest(reply);
ShutdownSession();
return 0;
@@ -318,7 +318,7 @@ void CVkProto::PollingThread(void*)
if (PollServer() == -1 || !m_hPollingThread)
break;
- m_pollingConn = nullptr;
+ ClosePollingConnection();
debugLogA("CVkProto::PollingThread: leaving");
if (m_hPollingThread) {
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index e77bea8472..88c2d6f408 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -366,6 +366,8 @@ private:
bool ApplyCaptcha(AsyncHttpRequest *pReq, const JSONNode&);
void ConnectionFailed(int iReason);
void OnLoggedIn();
+ void ClosePollingConnection();
+ void CloseAPIConnection();
void OnLoggedOut();
void ShutdownSession();
void SetAvatarUrl(MCONTACT hContact, CMStringW &wszUrl);
diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp
index fd5b1bc621..d89502e67d 100644
--- a/protocols/VKontakte/src/vk_queue.cpp
+++ b/protocols/VKontakte/src/vk_queue.cpp
@@ -82,7 +82,7 @@ void CVkProto::ExecuteRequest(AsyncHttpRequest *pReq)
debugLogA("CVkProto::ExecuteRequest pReq->bNeedsRestart = %d", (int)pReq->bNeedsRestart);
if (!reply && pReq->m_bApiReq)
- m_hAPIConnection = nullptr;
+ CloseAPIConnection();
} while (pReq->bNeedsRestart && !m_bTerminated);
delete pReq;
@@ -146,7 +146,7 @@ void CVkProto::WorkerThread(void*)
Push(pReq);
}
- m_hAPIConnection = nullptr;
+ CloseAPIConnection();
while (true) {
WaitForSingleObject(m_evRequestsQueue, 1000);
@@ -192,12 +192,7 @@ void CVkProto::WorkerThread(void*)
}
}
- if (m_hAPIConnection) {
- debugLogA("CVkProto::WorkerThread: Netlib_CloseHandle(m_hAPIConnection) beg");
- Netlib_CloseHandle(m_hAPIConnection);
- debugLogA("CVkProto::WorkerThread: Netlib_CloseHandle(m_hAPIConnection) end");
- m_hAPIConnection = nullptr;
- }
+ CloseAPIConnection();
debugLogA("CVkProto::WorkerThread: leaving m_bTerminated = %d", m_bTerminated ? 1 : 0);
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp
index 819389d0dc..9b5bc2c1d5 100644
--- a/protocols/VKontakte/src/vk_thread.cpp
+++ b/protocols/VKontakte/src/vk_thread.cpp
@@ -98,6 +98,20 @@ void CVkProto::OnLoggedIn()
db_unset(0, m_szModuleName, "LastNotificationsReqTime");
}
+void CVkProto::ClosePollingConnection()
+{
+ if (m_pollingConn)
+ Netlib_CloseHandle(m_pollingConn);
+ m_pollingConn = nullptr;
+}
+
+void CVkProto::CloseAPIConnection()
+{
+ if (m_hAPIConnection)
+ Netlib_CloseHandle(m_hAPIConnection);
+ m_hAPIConnection = nullptr;
+}
+
void CVkProto::OnLoggedOut()
{
debugLogA("CVkProto::OnLoggedOut");
@@ -113,11 +127,8 @@ void CVkProto::OnLoggedOut()
m_hWorkerThread = nullptr;
}
- if (m_hAPIConnection)
- Netlib_CloseHandle(m_hAPIConnection);
-
- if (m_pollingConn)
- Netlib_Shutdown(m_pollingConn);
+ CloseAPIConnection();
+ ClosePollingConnection();
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, ID_STATUS_OFFLINE);
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;