Skip to content

Commit

Permalink
Fix that not to delete some objects after destroying functions (ros2#236
Browse files Browse the repository at this point in the history
)

Signed-off-by: Chen.Lihui <lihui.chen@sony.com>
  • Loading branch information
Chen Lihui authored and eboasson committed May 17, 2021
1 parent d4226c8 commit 4183190
Showing 1 changed file with 10 additions and 6 deletions.
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 @@ -334,8 +334,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 @@ -3790,8 +3790,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 @@ -3891,8 +3891,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 @@ -3956,6 +3956,7 @@ static rmw_ret_t destroy_client(const rmw_node_t * node, rmw_client_t * client)
}

rmw_fini_cs(&info->client);
delete info;
rmw_free(const_cast<char *>(client->service_name));
rmw_client_free(client);
return RMW_RET_OK;
Expand Down Expand Up @@ -4012,6 +4013,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 @@ -4058,6 +4060,7 @@ static rmw_ret_t destroy_service(const rmw_node_t * node, rmw_service_t * servic
}

rmw_fini_cs(&info->service);
delete info;
rmw_free(const_cast<char *>(service->service_name));
rmw_service_free(service);
return RMW_RET_OK;
Expand Down Expand Up @@ -4112,6 +4115,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

0 comments on commit 4183190

Please sign in to comment.