Don't stack-allocate binder objects.
These inherit from RefBase and need to be owned in an sp<>.
Bug: 36854729
Test: manual on Pixel phone
Change-Id: I54dac1298dca1eb3ab5e6751366ba67bb2e1906c
diff --git a/services/vr/virtual_touchpad/main.cpp b/services/vr/virtual_touchpad/main.cpp
index e73f8b9..55ac9bf 100644
--- a/services/vr/virtual_touchpad/main.cpp
+++ b/services/vr/virtual_touchpad/main.cpp
@@ -8,8 +8,9 @@
int main() {
ALOGI("Starting");
- android::dvr::VirtualTouchpadService touchpad_service(
- android::dvr::VirtualTouchpadEvdev::Create());
+ android::sp<android::dvr::VirtualTouchpadService> touchpad_service =
+ new android::dvr::VirtualTouchpadService(
+ android::dvr::VirtualTouchpadEvdev::Create());
signal(SIGPIPE, SIG_IGN);
android::sp<android::ProcessState> ps(android::ProcessState::self());
@@ -19,8 +20,8 @@
android::sp<android::IServiceManager> sm(android::defaultServiceManager());
const android::status_t service_status =
- sm->addService(android::String16(touchpad_service.SERVICE_NAME()),
- &touchpad_service, false /*allowIsolated*/);
+ sm->addService(android::String16(touchpad_service->SERVICE_NAME()),
+ touchpad_service, false /*allowIsolated*/);
if (service_status != android::OK) {
ALOGE("virtual touchpad service not added: %d",
static_cast<int>(service_status));