Fix lifetime bug
Capturing a shared_ptr by reference does not keep it alive for the
lifetime of the callback, as was clearly the intent on this line. This
leads to use after free bugs.
Make the one character change to capture this RAII object by value, not
reference.
Tested: Don't have NVMe drives to test with at the moment, but this
should be trivial.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I5c81f0bd287f3ea3e3a77f3589718201733be32f
diff --git a/src/NVMeBasicContext.cpp b/src/NVMeBasicContext.cpp
index a99287f..93802b9 100644
--- a/src/NVMeBasicContext.cpp
+++ b/src/NVMeBasicContext.cpp
@@ -278,7 +278,7 @@
/* Issue the request */
boost::asio::async_write(
reqStream, boost::asio::buffer(command->data(), command->size()),
- [&command](boost::system::error_code ec, std::size_t) {
+ [command](boost::system::error_code ec, std::size_t) {
if (ec)
{
std::cerr << "Got error writing basic query: " << ec << "\n";