Fix regression in startBugreport flow
Ensure what's passed to the background thread is around.
BUG: 123617758
Test: adb shell /data/nativetest64/dumpstate_test/dumpstate_test
Test: manual test of API via a test client
Change-Id: I161c0d378c04cf925778fdb8712b1bd68901fb91
diff --git a/cmds/dumpstate/DumpstateService.cpp b/cmds/dumpstate/DumpstateService.cpp
index db3fe30..bb089e6 100644
--- a/cmds/dumpstate/DumpstateService.cpp
+++ b/cmds/dumpstate/DumpstateService.cpp
@@ -18,8 +18,9 @@
#include "DumpstateService.h"
-#include <android-base/stringprintf.h>
+#include <memory>
+#include <android-base/stringprintf.h>
#include "android/os/BnDumpstate.h"
#include "DumpstateInternal.h"
@@ -48,9 +49,10 @@
return binder::Status::fromServiceSpecificError(code, String8(msg.c_str()));
}
+// Takes ownership of data.
static void* callAndNotify(void* data) {
- DumpstateInfo& ds_info = *static_cast<DumpstateInfo*>(data);
- ds_info.ds->Run(ds_info.calling_uid, ds_info.calling_package);
+ std::unique_ptr<DumpstateInfo> ds_info(static_cast<DumpstateInfo*>(data));
+ ds_info->ds->Run(ds_info->calling_uid, ds_info->calling_package);
MYLOGD("Finished Run()\n");
return nullptr;
}
@@ -150,14 +152,16 @@
ds_->listener_ = listener;
}
- DumpstateInfo ds_info;
- ds_info.ds = ds_;
- ds_info.calling_uid = calling_uid;
- ds_info.calling_package = calling_package;
+ DumpstateInfo* ds_info = new DumpstateInfo();
+ ds_info->ds = ds_;
+ ds_info->calling_uid = calling_uid;
+ ds_info->calling_package = calling_package;
pthread_t thread;
- status_t err = pthread_create(&thread, nullptr, callAndNotify, &ds_);
+ status_t err = pthread_create(&thread, nullptr, callAndNotify, ds_info);
if (err != 0) {
+ delete ds_info;
+ ds_info = nullptr;
return error(err, "Could not create a background thread.");
}
return binder::Status::ok();