Fix memory leak in async_send_handler error path
If the handler throws in its error path, then this would cause a memory
leak (assuming that the executer is catching exceptions).
Change-Id: I44f0feaa7d317a7d8a23bc65a3d9cf6078539f44
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/sdbusplus/asio/detail/async_send_handler.hpp b/sdbusplus/asio/detail/async_send_handler.hpp
index ce4e394..58f6a34 100644
--- a/sdbusplus/asio/detail/async_send_handler.hpp
+++ b/sdbusplus/asio/detail/async_send_handler.hpp
@@ -45,10 +45,11 @@
sd_bus_call_async(conn, NULL, mesg.get(), &callback, context, 0);
if (ec < 0)
{
+ // add a deleter to context because handler may throw
+ std::unique_ptr<async_send_handler> safe_context(context);
auto err =
make_error_code(static_cast<boost::system::errc::errc_t>(ec));
context->handler_(err, mesg);
- delete context;
}
}
static int callback(sd_bus_message* mesg, void* userdata,
@@ -69,4 +70,4 @@
};
} // namespace detail
} // namespace asio
-} // namespace sdbusplus
\ No newline at end of file
+} // namespace sdbusplus