fix leak on resource search
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
f56a8feade
commit
8e7d84d05b
1 changed files with 29 additions and 12 deletions
|
@ -43,11 +43,16 @@ Task::Ptr NetworkResourceAPI::searchProjects(SearchArgs&& args, SearchCallbacks&
|
|||
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;
|
||||
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action)
|
||||
network_error_code = failed_action->replyStatusCode();
|
||||
|
||||
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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
|
||||
|
@ -153,11 +164,17 @@ Task::Ptr NetworkResourceAPI::getDependencyVersion(DependencySearchArgs&& args,
|
|||
|
||||
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);
|
||||
});
|
||||
return netJob;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue