Fix possible crash on MTP::Instance shutdown.

This commit is contained in:
John Preston 2023-05-25 11:50:06 +04:00
parent 2fb7bdc803
commit d57aa2a1f6
1 changed files with 12 additions and 3 deletions

View File

@ -557,13 +557,22 @@ void Session::tryToReceive() {
if (messages.empty()) {
break;
}
const auto guard = QPointer<Session>(this);
const auto instance = QPointer<Instance>(_instance);
const auto main = (_shiftedDcId == BareDcId(_shiftedDcId));
for (const auto &message : messages) {
if (message.requestId) {
_instance->processCallback(message);
} else if (_shiftedDcId == BareDcId(_shiftedDcId)) {
instance->processCallback(message);
} else if (main) {
// Process updates only in main session.
_instance->processUpdate(message);
instance->processUpdate(message);
}
if (!instance) {
return;
}
}
if (!guard) {
break;
}
}
}