Closed beta 1000014001: fixed crash in MTP destructor.

Some of MTP::Instance::Private fields access _instance in
destructors. All that cleanup should be performed before the
Instance::~Instance() (which invalidates _private) is called.
This commit is contained in:
John Preston 2017-02-25 20:55:11 +03:00
parent bcec2f6b84
commit d1e37864ac
1 changed files with 5 additions and 4 deletions

View File

@ -102,8 +102,7 @@ public:
void completedKeyDestroy(ShiftedDcId shiftedDcId); void completedKeyDestroy(ShiftedDcId shiftedDcId);
void clearKilledSessions(); void clearKilledSessions();
void prepareToDestroy();
~Private();
private: private:
bool hasAuthorization(); bool hasAuthorization();
@ -1189,7 +1188,7 @@ void Instance::Private::clearGlobalHandlers() {
setSessionResetHandler(base::lambda<void(ShiftedDcId)>()); setSessionResetHandler(base::lambda<void(ShiftedDcId)>());
} }
Instance::Private::~Private() { void Instance::Private::prepareToDestroy() {
for (auto &session : base::take(_sessions)) { for (auto &session : base::take(_sessions)) {
session.second->kill(); session.second->kill();
} }
@ -1371,6 +1370,8 @@ void Instance::onClearKilledSessions() {
_private->clearKilledSessions(); _private->clearKilledSessions();
} }
Instance::~Instance() = default; Instance::~Instance() {
_private->prepareToDestroy();
}
} // namespace MTP } // namespace MTP