Skip to content

Commit

Permalink
fix: dangling pointer issue by retaining shared_ptr
Browse files Browse the repository at this point in the history
修复因未保活智能指针导致指针悬空的问题

Log:
  • Loading branch information
myml authored and black-desk committed Jun 14, 2024
1 parent bf8489c commit bf9d84d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
1 change: 0 additions & 1 deletion libs/linglong/src/linglong/repo/client_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ QSharedPointer<api::client::ClientApi> ClientFactory::createClient() const
auto api = QSharedPointer<linglong::api::client::ClientApi>::create();
api->setTimeOut(5000);
api->setNewServerForAllOperations(m_server);
api->setParent(QCoreApplication::instance());
return api;
}

Expand Down
32 changes: 16 additions & 16 deletions libs/linglong/src/linglong/repo/ostree_repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,10 +848,10 @@ utils::error::Result<void> OSTreeRepo::push(const package::Reference &ref,
auth.setUsername(env.value("LINGLONG_USERNAME"));
auth.setPassword(env.value("LINGLONG_PASSWORD"));
qInfo() << "use username: " << auth.getUsername();
auto apiClient = this->m_clientFactory.createClient().data();
auto apiClient = this->m_clientFactory.createClient();
apiClient->setTimeOut(10 * 60 * 1000);
QEventLoop loop;
QEventLoop::connect(apiClient,
QEventLoop::connect(apiClient.data(),
&api::client::ClientApi::signInSignal,
&loop,
[&](api::client::SignIn_200_response resp) {
Expand All @@ -863,7 +863,7 @@ utils::error::Result<void> OSTreeRepo::push(const package::Reference &ref,
result = resp.getData().getToken();
return;
});
QEventLoop::connect(apiClient,
QEventLoop::connect(apiClient.data(),
&api::client::ClientApi::signInSignalEFull,
&loop,
[&](auto, auto error_type, const QString &error_str) {
Expand Down Expand Up @@ -892,9 +892,9 @@ utils::error::Result<void> OSTreeRepo::push(const package::Reference &ref,
uploadReq.setRef(ostreeSpecFromReference(ref, develop));
uploadReq.setRepoName(QString::fromStdString(this->cfg.defaultRepo));

auto apiClient = this->m_clientFactory.createClient().data();
auto apiClient = this->m_clientFactory.createClient();
QEventLoop loop;
QEventLoop::connect(apiClient,
QEventLoop::connect(apiClient.data(),
&api::client::ClientApi::newUploadTaskIDSignal,
&loop,
[&](const api::client::NewUploadTaskID_200_response &resp) {
Expand All @@ -905,7 +905,7 @@ utils::error::Result<void> OSTreeRepo::push(const package::Reference &ref,
}
result = resp.getData().getId();
});
QEventLoop::connect(apiClient,
QEventLoop::connect(apiClient.data(),
&api::client::ClientApi::newUploadTaskIDSignalEFull,
&loop,
[&](auto, auto error_type, const QString &error_str) {
Expand Down Expand Up @@ -946,9 +946,9 @@ utils::error::Result<void> OSTreeRepo::push(const package::Reference &ref,

utils::error::Result<void> result;

auto apiClient = this->m_clientFactory.createClient().data();
auto apiClient = this->m_clientFactory.createClient();
QEventLoop loop;
QEventLoop::connect(apiClient,
QEventLoop::connect(apiClient.data(),
&api::client::ClientApi::uploadTaskFileSignal,
&loop,
[&](const api::client::Api_UploadTaskFileResp &resp) {
Expand All @@ -958,7 +958,7 @@ utils::error::Result<void> OSTreeRepo::push(const package::Reference &ref,
return;
}
});
QEventLoop::connect(apiClient,
QEventLoop::connect(apiClient.data(),
&api::client::ClientApi::uploadTaskFileSignalEFull,
&loop,
[&](auto, auto error_type, const QString &error_str) {
Expand All @@ -983,10 +983,10 @@ utils::error::Result<void> OSTreeRepo::push(const package::Reference &ref,

utils::error::Result<bool> isFinished;

auto apiClient = this->m_clientFactory.createClient().data();
auto apiClient = this->m_clientFactory.createClient();
while (true) {
QEventLoop loop;
QEventLoop::connect(apiClient,
QEventLoop::connect(apiClient.data(),
&api::client::ClientApi::uploadTaskInfoSignal,
&loop,
[&](const api::client::UploadTaskInfo_200_response &resp) {
Expand All @@ -1010,7 +1010,7 @@ utils::error::Result<void> OSTreeRepo::push(const package::Reference &ref,

isFinished = false;
});
QEventLoop::connect(apiClient,
QEventLoop::connect(apiClient.data(),
&api::client::ClientApi::uploadTaskInfoSignalEFull,
&loop,
[&](auto, auto error_type, const QString &error_str) {
Expand Down Expand Up @@ -1150,7 +1150,7 @@ utils::error::Result<package::Reference> OSTreeRepo::clearReference(
qInfo() << reference.error();
qInfo() << "fallback to Remote";
}
auto apiClient = this->m_clientFactory.createClient().data();
auto apiClient = this->m_clientFactory.createClient();
reference =
clearReferenceRemote(fuzzy, *apiClient, QString::fromStdString(this->cfg.defaultRepo));
if (reference) {
Expand Down Expand Up @@ -1227,11 +1227,11 @@ OSTreeRepo::listRemote(const package::FuzzyReference &fuzzyRef) const noexcept

utils::error::Result<std::vector<api::types::v1::PackageInfoV2>> pkgInfos =
std::vector<api::types::v1::PackageInfoV2>{};
auto apiClient = this->m_clientFactory.createClient().data();
auto apiClient = this->m_clientFactory.createClient();
QEventLoop loop;
const qint32 HTTP_OK = 200;
QEventLoop::connect(
apiClient,
apiClient.data(),
&api::client::ClientApi::fuzzySearchAppSignal,
&loop,
[&](const api::client::FuzzySearchApp_200_response &resp) {
Expand Down Expand Up @@ -1259,7 +1259,7 @@ OSTreeRepo::listRemote(const package::FuzzyReference &fuzzyRef) const noexcept
return;
});

QEventLoop::connect(apiClient,
QEventLoop::connect(apiClient.data(),
&api::client::ClientApi::fuzzySearchAppSignalEFull,
&loop,
[&](auto, auto error_type, const QString &error_str) {
Expand Down

0 comments on commit bf9d84d

Please sign in to comment.