Skip to content

Commit

Permalink
Fix that not to delete some objects after destroying functions (#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 Sep 11, 2020
1 parent 8457daf commit 4a5b645
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 @@ -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 @@ -3716,8 +3716,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 @@ -3814,8 +3814,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 @@ -3871,6 +3871,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 @@ -3927,6 +3928,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 @@ -3965,6 +3967,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 @@ -4019,6 +4022,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 4a5b645

Please sign in to comment.