mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Fix possible crash on MTProto instance shutdown.
This commit is contained in:
@@ -1134,9 +1134,10 @@ void Instance::Private::processCallback(const Response &response) {
|
||||
QString::number(error.code()),
|
||||
error.type(),
|
||||
error.description()));
|
||||
if (rpcErrorOccured(response, handler, error)) {
|
||||
const auto guard = QPointer<Instance>(_instance);
|
||||
if (rpcErrorOccured(response, handler, error) && guard) {
|
||||
unregisterRequest(requestId);
|
||||
} else {
|
||||
} else if (guard) {
|
||||
QMutexLocker locker(&_parserMapLock);
|
||||
_parserMap.emplace(requestId, std::move(handler));
|
||||
}
|
||||
@@ -1156,12 +1157,15 @@ void Instance::Private::processCallback(const Response &response) {
|
||||
"RESPONSE_PARSE_FAILED",
|
||||
"Error parse failed.")));
|
||||
} else {
|
||||
if (handler.done && !handler.done(response)) {
|
||||
const auto guard = QPointer<Instance>(_instance);
|
||||
if (handler.done && !handler.done(response) && guard) {
|
||||
handleError(Error::Local(
|
||||
"RESPONSE_PARSE_FAILED",
|
||||
"Response parse failed."));
|
||||
}
|
||||
unregisterRequest(requestId);
|
||||
if (guard) {
|
||||
unregisterRequest(requestId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DEBUG_LOG(("RPC Info: parser not found for %1").arg(requestId));
|
||||
@@ -1192,8 +1196,11 @@ bool Instance::Private::rpcErrorOccured(
|
||||
const FailHandler &onFail,
|
||||
const Error &error) { // return true if need to clean request data
|
||||
if (IsDefaultHandledError(error)) {
|
||||
const auto guard = QPointer<Instance>(_instance);
|
||||
if (onFail && onFail(error, response)) {
|
||||
return true;
|
||||
} else if (!guard) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1208,7 +1215,11 @@ bool Instance::Private::rpcErrorOccured(
|
||||
? QString()
|
||||
: QString(": %1").arg(error.description())));
|
||||
if (onFail) {
|
||||
const auto guard = QPointer<Instance>(_instance);
|
||||
onFail(error, response);
|
||||
if (!guard) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user