diff options
author | 2022-07-19 17:48:55 +0000 | |
---|---|---|
committer | 2022-07-19 17:48:55 +0000 | |
commit | 752da342f9c8ee13ec0fd8a23f4138da8478d78b (patch) | |
tree | 4afe9912b69a4fcda9de78c0ea0504192a587168 /libs/binder/RpcState.cpp | |
parent | 28ae4e8753345848a85881ea50c9882e28216249 (diff) | |
parent | 17b7dc0d7df423f11e0fd25c152e5dc4d57f511c (diff) |
Merge "libbinder: RPC clear behavior" am: 4d9b036fbb am: 4abc23f79d am: 9d71de850e am: 17b7dc0d7d
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2154256
Change-Id: I25e2e120667c2c35ee85fb58f810e76fdb4ba6c5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'libs/binder/RpcState.cpp')
-rw-r--r-- | libs/binder/RpcState.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/libs/binder/RpcState.cpp b/libs/binder/RpcState.cpp index 1c5654c597..d063001414 100644 --- a/libs/binder/RpcState.cpp +++ b/libs/binder/RpcState.cpp @@ -244,33 +244,31 @@ void RpcState::clear() { "New state should be impossible after terminating!"); return; } + mTerminated = true; if (SHOULD_LOG_RPC_DETAIL) { ALOGE("RpcState::clear()"); dumpLocked(); } - // if the destructor of a binder object makes another RPC call, then calling - // decStrong could deadlock. So, we must hold onto these binders until - // mNodeMutex is no longer taken. - std::vector<sp<IBinder>> tempHoldBinder; - - mTerminated = true; + // invariants for (auto& [address, node] : mNodeForAddress) { - sp<IBinder> binder = node.binder.promote(); - LOG_ALWAYS_FATAL_IF(binder == nullptr, - "Binder expected to be owned with address: %" PRIu64 " %s", address, - node.toString().c_str()); - - if (node.sentRef != nullptr) { - tempHoldBinder.push_back(node.sentRef); + bool guaranteedHaveBinder = node.timesSent > 0; + if (guaranteedHaveBinder) { + LOG_ALWAYS_FATAL_IF(node.sentRef == nullptr, + "Binder expected to be owned with address: %" PRIu64 " %s", address, + node.toString().c_str()); } } - mNodeForAddress.clear(); + // if the destructor of a binder object makes another RPC call, then calling + // decStrong could deadlock. So, we must hold onto these binders until + // mNodeMutex is no longer taken. + auto temp = std::move(mNodeForAddress); + mNodeForAddress.clear(); // RpcState isn't reusable, but for future/explicit _l.unlock(); - tempHoldBinder.clear(); // explicit + temp.clear(); // explicit } void RpcState::dumpLocked() { |