Stop capturing mtp_event by reference in lambda
This takes a reference to the event,
which then can become invalid. Instead
pass by copy like normal.
Bug: 64529223
Test: No crash
Change-Id: I2ac7bd0002e6d0ce1c547c24334dfd2926ed7090
(cherry picked from commit 7360303d3e93cd6a5fd8c5c4340a335416bd0f28)
diff --git a/media/mtp/MtpFfsHandle.cpp b/media/mtp/MtpFfsHandle.cpp
index 23fd7ab..4132fed 100644
--- a/media/mtp/MtpFfsHandle.cpp
+++ b/media/mtp/MtpFfsHandle.cpp
@@ -724,7 +724,7 @@
char *temp = new char[me.length];
memcpy(temp, me.data, me.length);
me.data = temp;
- std::thread t([&me](MtpFfsHandle *h) { return h->doSendEvent(me); }, this);
+ std::thread t([this, me]() { return this->doSendEvent(me); });
t.detach();
return 0;
}
@@ -732,9 +732,9 @@
void MtpFfsHandle::doSendEvent(mtp_event me) {
unsigned length = me.length;
int ret = ::write(mIntr, me.data, length);
- delete[] reinterpret_cast<char*>(me.data);
if (static_cast<unsigned>(ret) != length)
PLOG(ERROR) << "Mtp error sending event thread!";
+ delete[] reinterpret_cast<char*>(me.data);
}
} // namespace android