From d9ef73bb587428b4e5e41eb965e225605f527f3e Mon Sep 17 00:00:00 2001 From: Petr Bena Date: Tue, 23 Dec 2014 17:51:18 +0100 Subject: [PATCH] did the same for other queries as well --- huggle/apiquery.cpp | 7 +++++++ huggle/webserverquery.cpp | 27 ++++++++++++++++++++++++++- huggle/webserverquery.hpp | 1 + huggle/wlquery.cpp | 9 +++++++-- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/huggle/apiquery.cpp b/huggle/apiquery.cpp index 5f9cea875..8c8f76839 100644 --- a/huggle/apiquery.cpp +++ b/huggle/apiquery.cpp @@ -250,6 +250,13 @@ void ApiQuery::Process() void ApiQuery::ReadData() { + // don't even try to do anything if query was killed + if (this->Status == StatusKilled) + return; + if (this->Result == nullptr) + throw new Huggle::NullPointerException("loc ApiQuery::Result", BOOST_CURRENT_FUNCTION); + if (this->reply == nullptr) + throw new Huggle::NullPointerException("loc ApiQuery::reply", BOOST_CURRENT_FUNCTION); this->Result->Data += QString(this->reply->readAll()); } diff --git a/huggle/webserverquery.cpp b/huggle/webserverquery.cpp index b286ecd8d..4855e4fdc 100644 --- a/huggle/webserverquery.cpp +++ b/huggle/webserverquery.cpp @@ -9,6 +9,7 @@ //GNU General Public License for more details. #include "webserverquery.hpp" +#include "exception.hpp" #include #include #include @@ -24,6 +25,17 @@ WebserverQuery::WebserverQuery() this->UsingPOST = false; } +Huggle::WebserverQuery::~WebserverQuery() +{ + if (this->reply != nullptr) + { + this->reply->abort(); + this->reply->disconnect(this); + this->reply->deleteLater(); + this->reply = nullptr; + } +} + void WebserverQuery::Process() { if (this->URL == "") @@ -61,12 +73,25 @@ void WebserverQuery::Kill() } void WebserverQuery::ReadData() -{ +{ // don't even try to do anything if query was killed + if (this->Status == StatusKilled) + return; + if (this->Result == nullptr) + throw new Huggle::NullPointerException("loc WebserverQuery::Result", BOOST_CURRENT_FUNCTION); + if (this->reply == nullptr) + throw new Huggle::NullPointerException("loc WebserverQuery::reply", BOOST_CURRENT_FUNCTION); this->Result->Data += QString(this->reply->readAll()); } void WebserverQuery::Finished() { + // don't even try to do anything if query was killed + if (this->Status == StatusKilled) + return; + if (this->Result == nullptr) + throw new Huggle::NullPointerException("loc WebserverQuery::Result", BOOST_CURRENT_FUNCTION); + if (this->reply == nullptr) + throw new Huggle::NullPointerException("loc WebserverQuery::reply", BOOST_CURRENT_FUNCTION); this->Result->Data += QString(this->reply->readAll()); // now we need to check if request was successful or not if (this->reply->error()) diff --git a/huggle/webserverquery.hpp b/huggle/webserverquery.hpp index 02f202fde..df0dca85e 100644 --- a/huggle/webserverquery.hpp +++ b/huggle/webserverquery.hpp @@ -28,6 +28,7 @@ namespace Huggle Q_OBJECT public: WebserverQuery(); + ~WebserverQuery(); //! Whether the query will submit parameters using POST data bool UsingPOST; //! This is an url of api request, you probably don't want to change it unless diff --git a/huggle/wlquery.cpp b/huggle/wlquery.cpp index d1a871272..893e6a345 100644 --- a/huggle/wlquery.cpp +++ b/huggle/wlquery.cpp @@ -27,8 +27,13 @@ WLQuery::WLQuery(WikiSite *site) WLQuery::~WLQuery() { - delete Result; - this->Result = nullptr; + if (this->networkReply != nullptr) + { + this->networkReply->abort(); + this->networkReply->disconnect(this); + this->networkReply->deleteLater(); + this->networkReply = nullptr; + } } QString WLQuery::QueryTypeToString()