Commit e352277b authored by Dominik Charousset's avatar Dominik Charousset

Fix memory leak in group_tunnel

parent bb1a8c30
...@@ -120,15 +120,17 @@ void group_tunnel::stop() { ...@@ -120,15 +120,17 @@ void group_tunnel::stop() {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
CAF_LOG_DEBUG("stop group tunnel:" << CAF_ARG2("module", module().name()) CAF_LOG_DEBUG("stop group tunnel:" << CAF_ARG2("module", module().name())
<< CAF_ARG2("identifier", identifier_)); << CAF_ARG2("identifier", identifier_));
auto hdl = actor{}; auto worker_hdl = actor{};
auto intermediary_hdl = actor{};
auto subs = subscriber_set{}; auto subs = subscriber_set{};
auto cache = cached_message_list{}; auto cache = cached_message_list{};
auto stopped = critical_section([this, &hdl, &subs, &cache] { auto stopped = critical_section([&, this] {
using std::swap; using std::swap;
if (!stopped_) { if (!stopped_) {
stopped_ = true; stopped_ = true;
swap(subs, subscribers_); swap(subs, subscribers_);
swap(hdl, worker_); swap(worker_hdl, worker_);
swap(intermediary_hdl, intermediary_);
swap(cache, cached_messages_); swap(cache, cached_messages_);
return true; return true;
} else { } else {
...@@ -136,7 +138,7 @@ void group_tunnel::stop() { ...@@ -136,7 +138,7 @@ void group_tunnel::stop() {
} }
}); });
if (stopped) { if (stopped) {
anon_send_exit(hdl, exit_reason::user_shutdown); anon_send_exit(worker_hdl, exit_reason::user_shutdown);
if (!subs.empty()) { if (!subs.empty()) {
auto bye = make_message(group_down_msg{group{this}}); auto bye = make_message(group_down_msg{group{this}});
for (auto& sub : subs) for (auto& sub : subs)
......
...@@ -83,8 +83,9 @@ struct testee_state { ...@@ -83,8 +83,9 @@ struct testee_state {
behavior testee_impl(stateful_actor<testee_state>* self) { behavior testee_impl(stateful_actor<testee_state>* self) {
return { return {
[=](put_atom, int x) { self->state.x = x; }, [self](put_atom, int x) { self->state.x = x; },
[=](get_atom) { return self->state.x; }, [self](get_atom) { return self->state.x; },
[self](const group_down_msg&) { self->quit(); },
}; };
} }
...@@ -103,9 +104,11 @@ struct fixture : test_coordinator_fixture<> { ...@@ -103,9 +104,11 @@ struct fixture : test_coordinator_fixture<> {
// Groups keep their subscribers alive (on purpose). Since we don't want to // Groups keep their subscribers alive (on purpose). Since we don't want to
// manually kill all our testee actors, we simply force the group modules to // manually kill all our testee actors, we simply force the group modules to
// stop here. // stop here.
uut->stop();
for (auto& kvp : uut->instances) for (auto& kvp : uut->instances)
kvp.second->stop(); kvp.second->stop();
sys.groups().get_module("local")->stop(); sys.groups().get_module("local")->stop();
run();
} }
void make_unconnected() { void make_unconnected() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment