diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index 6989c9b2d..2d3bc56f1 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -344,23 +344,6 @@ void Application::closeApplication() { if (_updateThread) _updateThread->quit(); _updateThread = 0; #endif - - DEBUG_LOG(("Telegram finished, result: %1").arg("unknown")); - -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - if (cRestartingUpdate()) { - DEBUG_LOG(("Application Info: executing updater to install update..")); - psExecUpdater(); - } else -#endif - if (cRestarting()) { - DEBUG_LOG(("Application Info: executing Telegram, because of restart..")); - psExecTelegram(); - } - - SignalHandlers::finish(); - PlatformSpecific::finish(); - Logs::finish(); } #ifndef TDESKTOP_DISABLE_AUTOUPDATE @@ -1067,7 +1050,7 @@ AppClass::~AppClass() { App::deinitMedia(); deinitImageLinkManager(); - MTP::stop(); + MTP::finish(); AppObject = 0; deleteAndMark(_uploader); diff --git a/Telegram/SourceFiles/main.cpp b/Telegram/SourceFiles/main.cpp index 2cbe3e078..571ef6f72 100644 --- a/Telegram/SourceFiles/main.cpp +++ b/Telegram/SourceFiles/main.cpp @@ -43,6 +43,26 @@ int main(int argc, char *argv[]) { //int a_argc = a_cnt + 1; //char *a_argv[a_cnt + 1] = { argv[0], args[0].data() }; - Application app(argc, argv); - return app.exec(); + int result = 0; + { + Application app(argc, argv); + result = app.exec(); + } + + DEBUG_LOG(("Telegram finished, result: %1").arg(result)); + +#ifndef TDESKTOP_DISABLE_AUTOUPDATE + if (cRestartingUpdate()) { + DEBUG_LOG(("Application Info: executing updater to install update..")); + psExecUpdater(); + } else +#endif + if (cRestarting()) { + DEBUG_LOG(("Application Info: executing Telegram, because of restart..")); + psExecTelegram(); + } + + SignalHandlers::finish(); + PlatformSpecific::finish(); + Logs::finish(); } diff --git a/Telegram/SourceFiles/mtproto/mtp.cpp b/Telegram/SourceFiles/mtproto/mtp.cpp index 4c2ce87fb..86493e522 100644 --- a/Telegram/SourceFiles/mtproto/mtp.cpp +++ b/Telegram/SourceFiles/mtproto/mtp.cpp @@ -758,6 +758,8 @@ namespace MTP { } void cancel(mtpRequestId requestId) { + if (!_started) return; + mtpMsgId msgId = 0; requestsDelays.remove(requestId); { @@ -831,7 +833,7 @@ namespace MTP { return MTP::RequestConnecting; } - void stop() { + void finish() { for (Sessions::iterator i = sessions.begin(), e = sessions.end(); i != e; ++i) { i.value()->kill(); delete i.value(); diff --git a/Telegram/SourceFiles/mtproto/mtp.h b/Telegram/SourceFiles/mtproto/mtp.h index 14a24470b..689665b81 100644 --- a/Telegram/SourceFiles/mtproto/mtp.h +++ b/Telegram/SourceFiles/mtproto/mtp.h @@ -132,9 +132,7 @@ namespace MTP { }; int32 state(mtpRequestId req); // < 0 means waiting for such count of ms - void defOnError(const RPCError &err); - - void stop(); + void finish(); void authed(int32 uid); int32 authedId(); diff --git a/Telegram/SourceFiles/mtproto/mtpFileLoader.cpp b/Telegram/SourceFiles/mtproto/mtpFileLoader.cpp index e53c69dce..f260f2ca4 100644 --- a/Telegram/SourceFiles/mtproto/mtpFileLoader.cpp +++ b/Telegram/SourceFiles/mtproto/mtpFileLoader.cpp @@ -527,7 +527,7 @@ void mtpFileLoader::cancelRequests() { _queue->queries -= _requests.size(); _requests.clear(); - if (!_queue->queries) { + if (!_queue->queries && App::app()) { App::app()->killDownloadSessionsStart(_dc); } } diff --git a/Telegram/SourceFiles/structs.cpp b/Telegram/SourceFiles/structs.cpp index 3664b9bf0..214622fcc 100644 --- a/Telegram/SourceFiles/structs.cpp +++ b/Telegram/SourceFiles/structs.cpp @@ -1393,6 +1393,12 @@ void DocumentData::recountIsImage() { DocumentData::~DocumentData() { delete _additional; + + if (loading()) { + _loader->deleteLater(); + _loader->stop(); + _loader = 0; + } } WebPageData::WebPageData(const WebPageId &id, WebPageType type, const QString &url, const QString &displayUrl, const QString &siteName, const QString &title, const QString &description, PhotoData *photo, DocumentData *doc, int32 duration, const QString &author, int32 pendingTill) : id(id)