From 83ba9855b52104162febda3ead7667c6cb56b225 2015-12-15 07:46:56 From: Jan Kaluza Date: 2015-12-15 07:46:56 Subject: [PATCH] Fix crash after HTTPRequestQueue destruction caused by HTTP response arriving after its destruction --- diff --git a/include/transport/HTTPRequestQueue.h b/include/transport/HTTPRequestQueue.h index 34e325cddc43494dbf3c52b4301b343936704d8f..7d4ef7410451eceeda7825cca7580bc82d880222 100644 --- a/include/transport/HTTPRequestQueue.h +++ b/include/transport/HTTPRequestQueue.h @@ -32,7 +32,7 @@ class HTTPRequestQueue { private: int m_delay; std::queue m_queue; - bool m_processing; + HTTPRequest *m_req; Swift::Timer::ref m_queueTimer; }; diff --git a/src/HTTPRequestQueue.cpp b/src/HTTPRequestQueue.cpp index 2484e311d05d259d09c7c7724caf0b6627c04a01..dba9c13e70308995790fd266b48300df364a60af 100644 --- a/src/HTTPRequestQueue.cpp +++ b/src/HTTPRequestQueue.cpp @@ -8,7 +8,7 @@ DEFINE_LOGGER(logger, "HTTPRequestQueue") HTTPRequestQueue::HTTPRequestQueue(Component *component, int delay) { m_delay = delay; - m_processing = false; + m_req = NULL; m_queueTimer = component->getNetworkFactories()->getTimerFactory()->createTimer(500); m_queueTimer->onTick.connect(boost::bind(&HTTPRequestQueue::sendNextRequest, this)); @@ -16,6 +16,10 @@ HTTPRequestQueue::HTTPRequestQueue(Component *component, int delay) { HTTPRequestQueue::~HTTPRequestQueue() { m_queueTimer->stop(); + + if (m_req) { + m_req->onRequestFinished.disconnect(boost::bind(&HTTPRequestQueue::handleRequestFinished, this)); + } } void HTTPRequestQueue::handleRequestFinished() { @@ -24,25 +28,25 @@ void HTTPRequestQueue::handleRequestFinished() { void HTTPRequestQueue::sendNextRequest() { if (m_queue.empty()) { - m_processing = false; + m_req = NULL; m_queueTimer->stop(); return; } - if (m_processing) { + if (m_req) { return; } - HTTPRequest *req = m_queue.front(); + m_req = m_queue.front(); m_queue.pop(); - req->onRequestFinished.connect(boost::bind(&HTTPRequestQueue::handleRequestFinished, this)); - req->execute(); + m_req->onRequestFinished.connect(boost::bind(&HTTPRequestQueue::handleRequestFinished, this)); + m_req->execute(); } void HTTPRequestQueue::queueRequest(HTTPRequest *req) { m_queue.push(req); - if (!m_processing) { + if (!m_req) { sendNextRequest(); } }