Avoid deallocating hwsm statics during shutdown.
We've had some reports of these being accessing during shutdown,
causing a crash. This is a common issue, since binder threads may still
be running while the main thread is shutdown. This is similar to
'DoNotDestruct' used elsewhere in libhidl*. Although, this class isn't
used again here since there are no ABI requirements to maintain.
Bug: 153909639
Test: boot on cuttlefish
Change-Id: Ic01dc15f739a0957f39aaf6a7b3e17fc4f7f6048
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index 3601016..d7faa6d 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -209,8 +209,8 @@
using android::hidl::manager::V1_2::BnHwServiceManager;
using android::hidl::manager::V1_2::BpHwServiceManager;
- static std::mutex gDefaultServiceManagerLock;
- static sp<IServiceManager1_2> gDefaultServiceManager;
+ static std::mutex& gDefaultServiceManagerLock = *new std::mutex;
+ static sp<IServiceManager1_2>& gDefaultServiceManager = *new sp<IServiceManager1_2>;
{
std::lock_guard<std::mutex> _l(gDefaultServiceManagerLock);