!2465 Bugfix for CoreServiceClient lifecyle.

Merge pull request !2465 from harrey/work
This commit is contained in:
openharmony_ci 2024-11-22 02:32:47 +00:00 committed by Gitee
commit 7f4ab30c77
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 14 additions and 2 deletions

View File

@ -31,6 +31,9 @@ CoreServiceClient::CoreServiceClient() = default;
CoreServiceClient::~CoreServiceClient()
{
RemoveDeathRecipient(nullptr, false);
if (deathRecipient_ != nullptr) {
reinterpret_cast<CoreServiceDeathRecipient*>(deathRecipient_.GetRefPtr())->SetValid(false);
}
}
sptr<ICoreService> CoreServiceClient::GetProxy()

View File

@ -16,6 +16,7 @@
#ifndef CORE_SERVICE_CLIENT_H
#define CORE_SERVICE_CLIENT_H
#include <atomic>
#include <cstdint>
#include <iremote_object.h>
#include <singleton.h>
@ -1212,15 +1213,23 @@ private:
void RemoveDeathRecipient(const wptr<IRemoteObject> &remote, bool isRemoteDied);
class CoreServiceDeathRecipient : public IRemoteObject::DeathRecipient {
public:
explicit CoreServiceDeathRecipient(CoreServiceClient &client) : client_(client) {}
explicit CoreServiceDeathRecipient(CoreServiceClient &client) : client_(client), isValid_(true) {}
~CoreServiceDeathRecipient() override = default;
__attribute__((no_sanitize("cfi"))) void OnRemoteDied(const wptr<IRemoteObject> &remote) override
{
if (isValid_.load()) {
client_.OnRemoteDied(remote);
}
}
void SetValid(bool isValid)
{
isValid_.store(isValid);
}
private:
CoreServiceClient &client_;
std::atomic_bool isValid_;
};
private: