mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix possible crash on MTProto instance shutdown.
This commit is contained in:
parent
17fa50bdff
commit
f442d69cb6
1 changed files with 15 additions and 4 deletions
|
@ -1134,9 +1134,10 @@ void Instance::Private::processCallback(const Response &response) {
|
||||||
QString::number(error.code()),
|
QString::number(error.code()),
|
||||||
error.type(),
|
error.type(),
|
||||||
error.description()));
|
error.description()));
|
||||||
if (rpcErrorOccured(response, handler, error)) {
|
const auto guard = QPointer<Instance>(_instance);
|
||||||
|
if (rpcErrorOccured(response, handler, error) && guard) {
|
||||||
unregisterRequest(requestId);
|
unregisterRequest(requestId);
|
||||||
} else {
|
} else if (guard) {
|
||||||
QMutexLocker locker(&_parserMapLock);
|
QMutexLocker locker(&_parserMapLock);
|
||||||
_parserMap.emplace(requestId, std::move(handler));
|
_parserMap.emplace(requestId, std::move(handler));
|
||||||
}
|
}
|
||||||
|
@ -1156,12 +1157,15 @@ void Instance::Private::processCallback(const Response &response) {
|
||||||
"RESPONSE_PARSE_FAILED",
|
"RESPONSE_PARSE_FAILED",
|
||||||
"Error parse failed.")));
|
"Error parse failed.")));
|
||||||
} else {
|
} else {
|
||||||
if (handler.done && !handler.done(response)) {
|
const auto guard = QPointer<Instance>(_instance);
|
||||||
|
if (handler.done && !handler.done(response) && guard) {
|
||||||
handleError(Error::Local(
|
handleError(Error::Local(
|
||||||
"RESPONSE_PARSE_FAILED",
|
"RESPONSE_PARSE_FAILED",
|
||||||
"Response parse failed."));
|
"Response parse failed."));
|
||||||
}
|
}
|
||||||
unregisterRequest(requestId);
|
if (guard) {
|
||||||
|
unregisterRequest(requestId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DEBUG_LOG(("RPC Info: parser not found for %1").arg(requestId));
|
DEBUG_LOG(("RPC Info: parser not found for %1").arg(requestId));
|
||||||
|
@ -1192,8 +1196,11 @@ bool Instance::Private::rpcErrorOccured(
|
||||||
const FailHandler &onFail,
|
const FailHandler &onFail,
|
||||||
const Error &error) { // return true if need to clean request data
|
const Error &error) { // return true if need to clean request data
|
||||||
if (IsDefaultHandledError(error)) {
|
if (IsDefaultHandledError(error)) {
|
||||||
|
const auto guard = QPointer<Instance>(_instance);
|
||||||
if (onFail && onFail(error, response)) {
|
if (onFail && onFail(error, response)) {
|
||||||
return true;
|
return true;
|
||||||
|
} else if (!guard) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1208,7 +1215,11 @@ bool Instance::Private::rpcErrorOccured(
|
||||||
? QString()
|
? QString()
|
||||||
: QString(": %1").arg(error.description())));
|
: QString(": %1").arg(error.description())));
|
||||||
if (onFail) {
|
if (onFail) {
|
||||||
|
const auto guard = QPointer<Instance>(_instance);
|
||||||
onFail(error, response);
|
onFail(error, response);
|
||||||
|
if (!guard) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue