Skip to content

Commit

Permalink
Set rmw_dds_common::GraphCache callback after init succeeds. (#496)
Browse files Browse the repository at this point in the history
Otherwise, during stack unwinding, the graph cache may end up
with a callback that captures and uses an already destroyed
guard condition.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic authored Dec 16, 2020
1 parent c3b958e commit 975861a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
15 changes: 8 additions & 7 deletions rmw_fastrtps_cpp/src/init_rmw_context_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,6 @@ init_context_impl(rmw_context_t * context)
return RMW_RET_BAD_ALLOC;
}

common_context->graph_cache.set_on_change_callback(
[guard_condition = graph_guard_condition.get()]() {
rmw_fastrtps_shared_cpp::__rmw_trigger_guard_condition(
eprosima_fastrtps_identifier,
guard_condition);
});

common_context->gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
eprosima_fastrtps_identifier, participant_info->participant->getGuid());
common_context->pub = publisher.get();
Expand All @@ -171,6 +164,14 @@ init_context_impl(rmw_context_t * context)
if (RMW_RET_OK != ret) {
return ret;
}

common_context->graph_cache.set_on_change_callback(
[guard_condition = graph_guard_condition.get()]() {
rmw_fastrtps_shared_cpp::__rmw_trigger_guard_condition(
eprosima_fastrtps_identifier,
guard_condition);
});

common_context->graph_cache.add_participant(
common_context->gid,
context->options.enclave);
Expand Down
16 changes: 8 additions & 8 deletions rmw_fastrtps_dynamic_cpp/src/init_rmw_context_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,6 @@ init_context_impl(rmw_context_t * context)
return RMW_RET_BAD_ALLOC;
}

common_context->graph_cache.set_on_change_callback(
[guard_condition = graph_guard_condition.get()]() {
rmw_fastrtps_shared_cpp::__rmw_trigger_guard_condition(
eprosima_fastrtps_identifier,
guard_condition);
});


common_context->gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
eprosima_fastrtps_identifier, participant_info->participant->getGuid());
common_context->pub = publisher.get();
Expand All @@ -172,6 +164,14 @@ init_context_impl(rmw_context_t * context)
if (RMW_RET_OK != ret) {
return ret;
}

common_context->graph_cache.set_on_change_callback(
[guard_condition = graph_guard_condition.get()]() {
rmw_fastrtps_shared_cpp::__rmw_trigger_guard_condition(
eprosima_fastrtps_identifier,
guard_condition);
});

common_context->graph_cache.add_participant(
common_context->gid,
context->options.enclave);
Expand Down

0 comments on commit 975861a

Please sign in to comment.