mirror of
https://gitee.com/openharmony/communication_ipc
synced 2024-11-27 10:01:19 +00:00
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:
parent
af09ba6fca
commit
5b8e5b6c36
@ -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) {}
|
||||
|
Loading…
Reference in New Issue
Block a user