Fix shared_ptr cycle in test_epee_connection.test_lifetime

This commit is contained in:
Lee Clagett 2022-08-26 20:12:13 -04:00
parent 5256fdd7a1
commit 3987827517
1 changed files with 5 additions and 2 deletions

View File

@ -212,11 +212,14 @@ TEST(test_epee_connection, test_lifetime)
server.get_config_shared()->set_handler(new command_handler_t, &command_handler_t::destroy); server.get_config_shared()->set_handler(new command_handler_t, &command_handler_t::destroy);
io_context.post([&io_context, &work, &endpoint, &server]{ io_context.post([&io_context, &work, &endpoint, &server]{
auto scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&work]{ shared_state_ptr shared_state;
auto scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&work, &shared_state]{
work.reset(); work.reset();
if (shared_state)
shared_state->set_handler(nullptr, nullptr);
}); });
shared_state_ptr shared_state(std::make_shared<shared_state_t>()); shared_state = std::make_shared<shared_state_t>();
shared_state->set_handler(new command_handler_t, &command_handler_t::destroy); shared_state->set_handler(new command_handler_t, &command_handler_t::destroy);
auto create_connection = [&io_context, &endpoint, &shared_state] { auto create_connection = [&io_context, &endpoint, &shared_state] {