Merge pull request #3103 from PrismLauncher/backport-3024-to-release-9.x
[Backport release-9.x] fix leak on resource search
This commit is contained in:
commit
2a4c4ed8ea
@ -43,11 +43,16 @@ Task::Ptr NetworkResourceAPI::searchProjects(SearchArgs&& args, SearchCallbacks&
|
|||||||
callbacks.on_succeed(doc);
|
callbacks.on_succeed(doc);
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(netJob.get(), &NetJob::failed, [netJob, callbacks](const QString& reason) {
|
// Capture a weak_ptr instead of a shared_ptr to avoid circular dependency issues.
|
||||||
|
// This prevents the lambda from extending the lifetime of the shared resource,
|
||||||
|
// as it only temporarily locks the resource when needed.
|
||||||
|
auto weak = netJob.toWeakRef();
|
||||||
|
QObject::connect(netJob.get(), &NetJob::failed, [weak, callbacks](const QString& reason) {
|
||||||
int network_error_code = -1;
|
int network_error_code = -1;
|
||||||
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action)
|
if (auto netJob = weak.lock()) {
|
||||||
network_error_code = failed_action->replyStatusCode();
|
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action)
|
||||||
|
network_error_code = failed_action->replyStatusCode();
|
||||||
|
}
|
||||||
callbacks.on_fail(reason, network_error_code);
|
callbacks.on_fail(reason, network_error_code);
|
||||||
});
|
});
|
||||||
QObject::connect(netJob.get(), &NetJob::aborted, [callbacks] { callbacks.on_abort(); });
|
QObject::connect(netJob.get(), &NetJob::aborted, [callbacks] { callbacks.on_abort(); });
|
||||||
@ -102,11 +107,17 @@ Task::Ptr NetworkResourceAPI::getProjectVersions(VersionSearchArgs&& args, Versi
|
|||||||
|
|
||||||
callbacks.on_succeed(doc, args.pack);
|
callbacks.on_succeed(doc, args.pack);
|
||||||
});
|
});
|
||||||
QObject::connect(netJob.get(), &NetJob::failed, [netJob, callbacks](const QString& reason) {
|
|
||||||
int network_error_code = -1;
|
|
||||||
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action)
|
|
||||||
network_error_code = failed_action->replyStatusCode();
|
|
||||||
|
|
||||||
|
// Capture a weak_ptr instead of a shared_ptr to avoid circular dependency issues.
|
||||||
|
// This prevents the lambda from extending the lifetime of the shared resource,
|
||||||
|
// as it only temporarily locks the resource when needed.
|
||||||
|
auto weak = netJob.toWeakRef();
|
||||||
|
QObject::connect(netJob.get(), &NetJob::failed, [weak, callbacks](const QString& reason) {
|
||||||
|
int network_error_code = -1;
|
||||||
|
if (auto netJob = weak.lock()) {
|
||||||
|
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action)
|
||||||
|
network_error_code = failed_action->replyStatusCode();
|
||||||
|
}
|
||||||
callbacks.on_fail(reason, network_error_code);
|
callbacks.on_fail(reason, network_error_code);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -153,11 +164,17 @@ Task::Ptr NetworkResourceAPI::getDependencyVersion(DependencySearchArgs&& args,
|
|||||||
|
|
||||||
callbacks.on_succeed(doc, args.dependency);
|
callbacks.on_succeed(doc, args.dependency);
|
||||||
});
|
});
|
||||||
QObject::connect(netJob.get(), &NetJob::failed, [netJob, callbacks](const QString& reason) {
|
|
||||||
int network_error_code = -1;
|
|
||||||
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action)
|
|
||||||
network_error_code = failed_action->replyStatusCode();
|
|
||||||
|
|
||||||
|
// Capture a weak_ptr instead of a shared_ptr to avoid circular dependency issues.
|
||||||
|
// This prevents the lambda from extending the lifetime of the shared resource,
|
||||||
|
// as it only temporarily locks the resource when needed.
|
||||||
|
auto weak = netJob.toWeakRef();
|
||||||
|
QObject::connect(netJob.get(), &NetJob::failed, [weak, callbacks](const QString& reason) {
|
||||||
|
int network_error_code = -1;
|
||||||
|
if (auto netJob = weak.lock()) {
|
||||||
|
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action)
|
||||||
|
network_error_code = failed_action->replyStatusCode();
|
||||||
|
}
|
||||||
callbacks.on_fail(reason, network_error_code);
|
callbacks.on_fail(reason, network_error_code);
|
||||||
});
|
});
|
||||||
return netJob;
|
return netJob;
|
||||||
|
Loading…
Reference in New Issue
Block a user