diff options
author | Vernon Mauery <vernon.mauery@linux.intel.com> | 2018-09-21 13:14:23 -0700 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2018-09-24 13:43:33 +0000 |
commit | 6693995afe5658ca29e940403f9f09f7c09fddf4 (patch) | |
tree | 0816bfb92bd296948723332a643b864fd8d7237f /sdbusplus/asio | |
parent | 33335b35533cc1e08096bc74f09283e68eb36205 (diff) | |
download | sdbusplus-6693995afe5658ca29e940403f9f09f7c09fddf4.tar.gz sdbusplus-6693995afe5658ca29e940403f9f09f7c09fddf4.zip |
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>
Diffstat (limited to 'sdbusplus/asio')
-rw-r--r-- | sdbusplus/asio/detail/async_send_handler.hpp | 5 |
1 files changed, 3 insertions, 2 deletions
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 @@ struct async_send_handler 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 @@ struct async_send_handler }; } // namespace detail } // namespace asio -} // namespace sdbusplus
\ No newline at end of file +} // namespace sdbusplus |