From 8ef06acf351fdb6034b6e13670d84bfd79161956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Fri, 28 Nov 2014 21:13:59 +0000 Subject: Steam: Fix polling thread memleak, handle (max 3) errors and eventually disconnect (finally); version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@11135 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Steam/src/steam_pooling.cpp | 21 +++++++++++++++++---- protocols/Steam/src/version.h | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'protocols/Steam') diff --git a/protocols/Steam/src/steam_pooling.cpp b/protocols/Steam/src/steam_pooling.cpp index 3a375d4ab3..64d72acb09 100644 --- a/protocols/Steam/src/steam_pooling.cpp +++ b/protocols/Steam/src/steam_pooling.cpp @@ -1,5 +1,7 @@ #include "common.h" +#define POLLING_ERRORS_LIMIT 3 + void CSteamProto::ParsePollData(JSONNODE *data) { JSONNODE *node, *item = NULL; @@ -175,8 +177,9 @@ void CSteamProto::PollingThread(void*) UINT32 messageId = getDword("MessageID", 0); //SteamWebApi::PollApi::PollResult pollResult; + int errors = 0; bool breaked = false; - while (!isTerminated && !breaked) + while (!isTerminated && !breaked && errors < POLLING_ERRORS_LIMIT) { SteamWebApi::PollRequest *request = new SteamWebApi::PollRequest(token, umqId, messageId); debugLogA("CSteamProto::PollingThread: %s", request->szUrl); @@ -186,7 +189,15 @@ void CSteamProto::PollingThread(void*) delete request; if (response == NULL || response->resultCode != HTTP_STATUS_OK) - return; + { + if (response != NULL) + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response); + + errors++; + continue; + } + else + errors = 0; JSONROOT root(response->pData); JSONNODE *node = json_get(root, "error"); @@ -241,7 +252,9 @@ void CSteamProto::PollingThread(void*) m_hPollingThread = NULL; debugLogA("CSteamProto::PollingThread: leaving"); - // if something wrong, switch proto to offline - if (breaked) + if (!isTerminated) + { + debugLogA("CSteamProto::PollingThread: unexpected termination; switching protocol to offline"); SetStatus(ID_STATUS_OFFLINE); + } } \ No newline at end of file diff --git a/protocols/Steam/src/version.h b/protocols/Steam/src/version.h index 065a552217..d81bbde9e0 100644 --- a/protocols/Steam/src/version.h +++ b/protocols/Steam/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 11 #define __RELEASE_NUM 0 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include -- cgit v1.2.3