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 all 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
16 changes: 10 additions & 6 deletions rmw_cyclonedds_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ struct client_service_id_t

struct CddsCS
{
CddsPublisher * pub;
CddsSubscription * sub;
std::unique_ptr<CddsPublisher> pub;
std::unique_ptr<CddsSubscription> sub;
client_service_id_t id;
};

Expand Down Expand Up @@ -3704,8 +3704,8 @@ static rmw_ret_t rmw_init_cs(
const rosidl_service_type_support_t * type_support = get_service_typesupport(type_supports);
RET_NULL(type_support);

auto pub = new CddsPublisher();
auto sub = new CddsSubscription();
auto pub = std::make_unique<CddsPublisher>();
auto sub = std::make_unique<CddsSubscription>();
std::string subtopic_name, pubtopic_name;
void * pub_type_support, * sub_type_support;

Expand Down Expand Up @@ -3802,8 +3802,8 @@ static rmw_ret_t rmw_init_cs(
dds_delete(subtopic);
dds_delete(pubtopic);

cs->pub = pub;
cs->sub = sub;
cs->pub = std::move(pub);
cs->sub = std::move(sub);
return RMW_RET_OK;

fail_instance_handle:
Expand Down Expand Up @@ -3859,6 +3859,7 @@ static rmw_ret_t destroy_client(const rmw_node_t * node, rmw_client_t * client)
}

rmw_fini_cs(&info->client);
delete info;
iuhilnehc-ynos marked this conversation as resolved.
Show resolved Hide resolved
rmw_free(const_cast<char *>(client->service_name));
rmw_client_free(client);
return RMW_RET_OK;
Expand Down Expand Up @@ -3915,6 +3916,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 Down Expand Up @@ -3953,6 +3955,7 @@ static rmw_ret_t destroy_service(const rmw_node_t * node, rmw_service_t * servic
}

rmw_fini_cs(&info->service);
delete info;
iuhilnehc-ynos marked this conversation as resolved.
Show resolved Hide resolved
rmw_free(const_cast<char *>(service->service_name));
rmw_service_free(service);
return RMW_RET_OK;
Expand Down Expand Up @@ -4007,6 +4010,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