update ipc/native/src/jni/source/ohos_rpc_remote_object.cpp.

[master]fix RemoteObject mem leak

Signed-off-by: 马根堂 <magentang4@huawei.com>
This commit is contained in:
马根堂 2023-06-26 11:45:41 +00:00 committed by Gitee
parent af09ba6fca
commit 5b8e5b6c36
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -96,7 +96,7 @@ public:
private:
std::mutex mutex_;
std::u16string descriptor_;
wptr<JRemoteObject> cachedObject_;
sptr<JRemoteObject> cachedObject_;
};
/*
@ -248,12 +248,16 @@ sptr<JRemoteObject> JRemoteObjectHolder::Get(jobject object)
std::lock_guard<std::mutex> lockGuard(mutex_);
// grab an strong reference to the object,
// so it will not be freed util this reference released.
sptr<JRemoteObject> tmp = cachedObject_.promote();
if (tmp == nullptr) {
tmp = new JRemoteObject(object, descriptor_);
cachedObject_ = tmp;
sptr<JRemoteObject> remoteObject = nullptr;
if (cachedObject_ != nullptr) {
remoteObject = cachedObject_;
}
return tmp;
if (remoteObject == nullptr) {
remoteObject = new JRemoteObject(object, descriptor_);
cachedObject_ = remoteObject;
}
return remoteObject;
}
JRemoteProxyHolder::JRemoteProxyHolder() : list_(nullptr), object_(nullptr) {}