From aa0bf0a8b34815cbf4ecac9e36c2a809385bd458 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Sat, 2 Dec 2017 08:21:52 +1100 Subject: [PATCH] Reapply double delete fix, which was overwritten by Networking TS merge. --- .../boost/asio/detail/impl/epoll_reactor.ipp | 18 ++++++++++++++++++ .../boost/asio/detail/impl/kqueue_reactor.ipp | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/boost/asio/detail/impl/epoll_reactor.ipp b/include/boost/asio/detail/impl/epoll_reactor.ipp index f66e8e59..a9c2602f 100644 --- a/include/boost/asio/detail/impl/epoll_reactor.ipp +++ b/include/boost/asio/detail/impl/epoll_reactor.ipp @@ -385,6 +385,15 @@ void epoll_reactor::deregister_descriptor(socket_type descriptor, reinterpret_cast(descriptor_data))); scheduler_.post_deferred_completions(ops); + + // Leave descriptor_data set so that it will be freed by the subsequent + // call to cleanup_descriptor_data. + } + else + { + // We are shutting down, so prevent cleanup_descriptor_data from freeing + // the descriptor_data object and let the destructor free it instead. + descriptor_data = 0; } } @@ -413,6 +422,15 @@ void epoll_reactor::deregister_internal_descriptor(socket_type descriptor, BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(( context(), static_cast(descriptor), reinterpret_cast(descriptor_data))); + + // Leave descriptor_data set so that it will be freed by the subsequent + // call to cleanup_descriptor_data. + } + else + { + // We are shutting down, so prevent cleanup_descriptor_data from freeing + // the descriptor_data object and let the destructor free it instead. + descriptor_data = 0; } } diff --git a/include/boost/asio/detail/impl/kqueue_reactor.ipp b/include/boost/asio/detail/impl/kqueue_reactor.ipp index 8656880e..c492646a 100644 --- a/include/boost/asio/detail/impl/kqueue_reactor.ipp +++ b/include/boost/asio/detail/impl/kqueue_reactor.ipp @@ -329,6 +329,15 @@ void kqueue_reactor::deregister_descriptor(socket_type descriptor, reinterpret_cast(descriptor_data))); scheduler_.post_deferred_completions(ops); + + // Leave descriptor_data set so that it will be freed by the subsequent + // call to cleanup_descriptor_data. + } + else + { + // We are shutting down, so prevent cleanup_descriptor_data from freeing + // the descriptor_data object and let the destructor free it instead. + descriptor_data = 0; } } @@ -361,6 +370,15 @@ void kqueue_reactor::deregister_internal_descriptor(socket_type descriptor, BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(( context(), static_cast(descriptor), reinterpret_cast(descriptor_data))); + + // Leave descriptor_data set so that it will be freed by the subsequent + // call to cleanup_descriptor_data. + } + else + { + // We are shutting down, so prevent cleanup_descriptor_data from freeing + // the descriptor_data object and let the destructor free it instead. + descriptor_data = 0; } }