From b098318c5ab5734bdc00defad2cb6b2eeffa3b72 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Fri, 2 Apr 2021 03:14:04 +0000 Subject: servicemanager: use safer ref base semantics Bug: 184190315 Test: N/A Change-Id: Iafa793f4f4a69651a281888a13369b802006be0e --- cmds/servicemanager/ServiceManager.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'cmds/servicemanager/ServiceManager.cpp') diff --git a/cmds/servicemanager/ServiceManager.cpp b/cmds/servicemanager/ServiceManager.cpp index 0dbab4e055..2f5524940e 100644 --- a/cmds/servicemanager/ServiceManager.cpp +++ b/cmds/servicemanager/ServiceManager.cpp @@ -239,7 +239,8 @@ Status ServiceManager::addService(const std::string& name, const sp& bi #endif // !VENDORSERVICEMANAGER // implicitly unlinked when the binder is removed - if (binder->remoteBinder() != nullptr && binder->linkToDeath(this) != OK) { + if (binder->remoteBinder() != nullptr && + binder->linkToDeath(sp::fromExisting(this)) != OK) { LOG(ERROR) << "Could not linkToDeath when adding " << name; return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); } @@ -307,7 +308,9 @@ Status ServiceManager::registerForNotifications( return Status::fromExceptionCode(Status::EX_NULL_POINTER); } - if (OK != IInterface::asBinder(callback)->linkToDeath(this)) { + if (OK != + IInterface::asBinder(callback)->linkToDeath( + sp::fromExisting(this))) { LOG(ERROR) << "Could not linkToDeath when adding " << name; return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); } @@ -461,7 +464,8 @@ Status ServiceManager::registerClientCallback(const std::string& name, const sp< return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); } - if (OK != IInterface::asBinder(cb)->linkToDeath(this)) { + if (OK != + IInterface::asBinder(cb)->linkToDeath(sp::fromExisting(this))) { LOG(ERROR) << "Could not linkToDeath when adding client callback for " << name; return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); } @@ -491,7 +495,7 @@ void ServiceManager::removeClientCallback(const wp& who, } ssize_t ServiceManager::Service::getNodeStrongRefCount() { - sp bpBinder = binder->remoteBinder(); + sp bpBinder = sp::fromExisting(binder->remoteBinder()); if (bpBinder == nullptr) return -1; return ProcessState::self()->getStrongRefCountForNode(bpBinder); -- cgit v1.2.3-59-g8ed1b