Skip to content

Commit

Permalink
Previous fix introduced a leak, use a better approach.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskohlhoff committed Aug 12, 2017
1 parent c8d628a commit b002097
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
25 changes: 20 additions & 5 deletions include/boost/asio/detail/impl/epoll_reactor.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ void epoll_reactor::deregister_descriptor(socket_type descriptor,
descriptor_lock.unlock();

io_service_.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;
}
}

Expand All @@ -384,6 +393,15 @@ void epoll_reactor::deregister_internal_descriptor(socket_type descriptor,
descriptor_data->shutdown_ = true;

descriptor_lock.unlock();

// 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;
}
}

Expand All @@ -392,11 +410,8 @@ void epoll_reactor::cleanup_descriptor_data(
{
if (descriptor_data)
{
if (!descriptor_data->shutdown_)
{
free_descriptor_state(descriptor_data);
descriptor_data = 0;
}
free_descriptor_state(descriptor_data);
descriptor_data = 0;
}
}

Expand Down
25 changes: 20 additions & 5 deletions include/boost/asio/detail/impl/kqueue_reactor.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,15 @@ void kqueue_reactor::deregister_descriptor(socket_type descriptor,
descriptor_lock.unlock();

io_service_.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;
}
}

Expand Down Expand Up @@ -341,6 +350,15 @@ void kqueue_reactor::deregister_internal_descriptor(socket_type descriptor,
descriptor_data->shutdown_ = true;

descriptor_lock.unlock();

// 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;
}
}

Expand All @@ -349,11 +367,8 @@ void kqueue_reactor::cleanup_descriptor_data(
{
if (descriptor_data)
{
if (!descriptor_data->shutdown_)
{
free_descriptor_state(descriptor_data);
descriptor_data = 0;
}
free_descriptor_state(descriptor_data);
descriptor_data = 0;
}
}

Expand Down

0 comments on commit b002097

Please sign in to comment.