From 68c31fd58da09d3f4f0b4c7b78a53f83cc5f9ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Thu, 5 Mar 2015 14:36:10 +0000 Subject: Steam: Fix potential memleaks when proto tries to do request when it became (or is already) offline git-svn-id: http://svn.miranda-ng.org/main/trunk@12325 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Steam/src/steam_proto.h | 10 +++++----- protocols/Steam/src/steam_queue.cpp | 26 +++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'protocols/Steam') diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 7824578824..705b2e080b 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -69,16 +69,16 @@ struct QueueItem SteamWebApi::HttpRequest *request; void *arg; RESPONSE responseCallback; - RESPONSE responseFailedCallback; + //RESPONSE responseFailedCallback; QueueItem(SteamWebApi::HttpRequest *request) : - request(request), arg(NULL), responseCallback(NULL), responseFailedCallback(NULL) { } + request(request), arg(NULL), responseCallback(NULL)/*, responseFailedCallback(NULL)*/ { } QueueItem(SteamWebApi::HttpRequest *request, RESPONSE response) : - request(request), arg(NULL), responseCallback(response), responseFailedCallback(NULL) { } + request(request), arg(NULL), responseCallback(response)/*, responseFailedCallback(NULL)*/ { } - QueueItem(SteamWebApi::HttpRequest *request, RESPONSE response, RESPONSE responseFailedCallback) : - request(request), arg(NULL), responseCallback(response), responseFailedCallback(responseFailedCallback) { } + //QueueItem(SteamWebApi::HttpRequest *request, RESPONSE response, RESPONSE responseFailedCallback) : + // request(request), arg(NULL), responseCallback(response), responseFailedCallback(responseFailedCallback) { } ~QueueItem() { delete request; responseCallback = NULL; } }; diff --git a/protocols/Steam/src/steam_queue.cpp b/protocols/Steam/src/steam_queue.cpp index a134aa9890..d5eb363ca0 100644 --- a/protocols/Steam/src/steam_queue.cpp +++ b/protocols/Steam/src/steam_queue.cpp @@ -45,9 +45,15 @@ void CSteamProto::StopQueue() { mir_cslock lock(requests_queue_lock); - int count = requestsQueue.getCount(); - while (count > 0) - requestsQueue.remove(--count); + while (requestsQueue.getCount() > 0) + { + QueueItem *item = requestsQueue[0]; + requestsQueue.remove(0); + + // We call ExecuteRequest() but as we have set isTerminated=true it will only run callback to behave correctly (free arguments, raise errors, etc.) + if (item != NULL) + ExecuteRequest(item); + } } // logoff @@ -76,6 +82,13 @@ void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request, RESPONSE respon void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response, void *arg) { + if (isTerminated || !IsOnline()) + { + // Call response callback so it can react properly (free arguments, raise errors, etc.) + if (response != NULL) + (this->*(response))(NULL, arg); + } + if (isTerminated) return; @@ -91,6 +104,13 @@ void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request, RESPONSE respon void CSteamProto::ExecuteRequest(QueueItem *item) { + if (isTerminated || !IsOnline()) + { + // Call response callback so it can react properly (free arguments, raise errors, etc.) + if (item->responseCallback != NULL) + (this->*(item->responseCallback))(NULL, item->arg); + } + if (isTerminated) return; -- cgit v1.2.3