Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix that not to delete some objects after destroying functions #236

Merged
merged 4 commits into from
Sep 11, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 59 additions & 38 deletions rmw_cyclonedds_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3819,6 +3819,8 @@ static rmw_ret_t rmw_init_cs(
fail_subtopic:
dds_delete(pubtopic);
fail_pubtopic:
delete sub;
delete pub;
return RMW_RET_ERROR;
}

Expand All @@ -3827,6 +3829,14 @@ static void rmw_fini_cs(CddsCS * cs)
dds_delete(cs->sub->rdcondh);
dds_delete(cs->sub->enth);
dds_delete(cs->pub->enth);
if (cs->sub) {
delete cs->sub;
cs->sub = NULL;
}
if (cs->pub) {
delete cs->pub;
cs->pub = NULL;
}
iuhilnehc-ynos marked this conversation as resolved.
Show resolved Hide resolved
}

static rmw_ret_t destroy_client(const rmw_node_t * node, rmw_client_t * client)
Expand All @@ -3835,30 +3845,34 @@ static rmw_ret_t destroy_client(const rmw_node_t * node, rmw_client_t * client)
RET_WRONG_IMPLID(node);
RET_NULL(client);
RET_WRONG_IMPLID(client);
auto info = static_cast<CddsClient *>(client->data);
clean_waitset_caches();

{
// Update graph
auto common = &node->context->impl->common;
std::lock_guard<std::mutex> guard(common->node_update_mutex);
static_cast<void>(common->graph_cache.dissociate_writer(
info->client.pub->gid, common->gid,
node->name, node->namespace_));
rmw_dds_common::msg::ParticipantEntitiesInfo msg =
common->graph_cache.dissociate_reader(
info->client.sub->gid, common->gid, node->name,
node->namespace_);
if (RMW_RET_OK != rmw_publish(
common->pub,
static_cast<void *>(&msg),
nullptr))
if (client->data) {
iuhilnehc-ynos marked this conversation as resolved.
Show resolved Hide resolved
auto info = static_cast<CddsClient *>(client->data);
{
RMW_SET_ERROR_MSG("failed to publish ParticipantEntitiesInfo when destroying service");
// Update graph
auto common = &node->context->impl->common;
std::lock_guard<std::mutex> guard(common->node_update_mutex);
static_cast<void>(common->graph_cache.dissociate_writer(
info->client.pub->gid, common->gid,
node->name, node->namespace_));
rmw_dds_common::msg::ParticipantEntitiesInfo msg =
common->graph_cache.dissociate_reader(
info->client.sub->gid, common->gid, node->name,
node->namespace_);
if (RMW_RET_OK != rmw_publish(
common->pub,
static_cast<void *>(&msg),
nullptr))
{
RMW_SET_ERROR_MSG("failed to publish ParticipantEntitiesInfo when destroying service");
}
}
}

rmw_fini_cs(&info->client);
rmw_fini_cs(&info->client);
delete info;
client->data = NULL;
}
rmw_free(const_cast<char *>(client->service_name));
rmw_client_free(client);
return RMW_RET_OK;
Expand Down Expand Up @@ -3915,6 +3929,7 @@ extern "C" rmw_client_t * rmw_create_client(
rmw_client_free(rmw_client);
fail_client:
rmw_fini_cs(&info->client);
delete info;
return nullptr;
}

Expand All @@ -3929,30 +3944,35 @@ static rmw_ret_t destroy_service(const rmw_node_t * node, rmw_service_t * servic
RET_WRONG_IMPLID(node);
RET_NULL(service);
RET_WRONG_IMPLID(service);
auto info = static_cast<CddsService *>(service->data);
clean_waitset_caches();

{
// Update graph
auto common = &node->context->impl->common;
std::lock_guard<std::mutex> guard(common->node_update_mutex);
static_cast<void>(common->graph_cache.dissociate_writer(
info->service.pub->gid, common->gid,
node->name, node->namespace_));
rmw_dds_common::msg::ParticipantEntitiesInfo msg =
common->graph_cache.dissociate_reader(
info->service.sub->gid, common->gid, node->name,
node->namespace_);
if (RMW_RET_OK != rmw_publish(
common->pub,
static_cast<void *>(&msg),
nullptr))
if (service->data) {
auto info = static_cast<CddsService *>(service->data);

{
RMW_SET_ERROR_MSG("failed to publish ParticipantEntitiesInfo when destroying service");
// Update graph
auto common = &node->context->impl->common;
std::lock_guard<std::mutex> guard(common->node_update_mutex);
static_cast<void>(common->graph_cache.dissociate_writer(
info->service.pub->gid, common->gid,
node->name, node->namespace_));
rmw_dds_common::msg::ParticipantEntitiesInfo msg =
common->graph_cache.dissociate_reader(
info->service.sub->gid, common->gid, node->name,
node->namespace_);
if (RMW_RET_OK != rmw_publish(
common->pub,
static_cast<void *>(&msg),
nullptr))
{
RMW_SET_ERROR_MSG("failed to publish ParticipantEntitiesInfo when destroying service");
}
}
}

rmw_fini_cs(&info->service);
rmw_fini_cs(&info->service);
delete info;
service->data = NULL;
}
rmw_free(const_cast<char *>(service->service_name));
rmw_service_free(service);
return RMW_RET_OK;
Expand Down Expand Up @@ -4007,6 +4027,7 @@ extern "C" rmw_service_t * rmw_create_service(
rmw_service_free(rmw_service);
fail_service:
rmw_fini_cs(&info->service);
delete info;
return nullptr;
}

Expand Down