Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #245 from ros2/fix_more_memory_leaks
Browse files Browse the repository at this point in the history
fix more memory leaks
  • Loading branch information
dirk-thomas committed Sep 2, 2017
2 parents 3113a5e + 220961b commit 188147a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
33 changes: 27 additions & 6 deletions rmw_connext_cpp/src/rmw_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ rmw_create_client(
goto fail;
}

// allocating memory for service_str and partition strings
if (!_process_service_name(
service_name,
qos_profile->avoid_ros_namespace_conventions,
Expand All @@ -132,6 +133,8 @@ rmw_create_client(
reinterpret_cast<void **>(&response_datareader),
reinterpret_cast<void **>(&request_datawriter),
&rmw_allocate);
DDS_String_free(service_str);
service_str = nullptr;
if (!requester) {
RMW_SET_ERROR_MSG("failed to create requester");
goto fail;
Expand Down Expand Up @@ -161,18 +164,28 @@ rmw_create_client(

// we have to set the partition array to length 1
// and then set the partition_str in it
if (response_partition_str && strlen(response_partition_str) != 0) {
subscriber_qos.partition.name.ensure_length(1, 1);
subscriber_qos.partition.name[0] = response_partition_str;
if (response_partition_str) {
if (strlen(response_partition_str) != 0) {
subscriber_qos.partition.name.ensure_length(1, 1);
// passing ownership to Connext
subscriber_qos.partition.name[0] = response_partition_str;
} else {
DDS_String_free(response_partition_str);
}
}
// update attached subscriber
dds_subscriber->set_qos(subscriber_qos);

// we cannot assign the partition_ptr again,
// as rti takes ownership over it.
if (request_partition_str && strlen(response_partition_str) != 0) {
publisher_qos.partition.name.ensure_length(1, 1);
publisher_qos.partition.name[0] = request_partition_str;
if (request_partition_str) {
if (strlen(request_partition_str) != 0) {
publisher_qos.partition.name.ensure_length(1, 1);
// passing ownership to Connext
publisher_qos.partition.name[0] = request_partition_str;
} else {
DDS_String_free(request_partition_str);
}
}
// update attached publisher
dds_publisher->set_qos(publisher_qos);
Expand Down Expand Up @@ -243,6 +256,14 @@ rmw_create_client(

return client;
fail:
if (request_partition_str) {
DDS_String_free(request_partition_str);
request_partition_str = nullptr;
}
if (response_partition_str) {
DDS_String_free(response_partition_str);
response_partition_str = nullptr;
}
if (client) {
rmw_client_free(client);
}
Expand Down
33 changes: 27 additions & 6 deletions rmw_connext_cpp/src/rmw_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ rmw_create_service(
goto fail;
}

// allocating memory for service_str and partition strings
if (!_process_service_name(
service_name,
qos_profile->avoid_ros_namespace_conventions,
Expand All @@ -128,6 +129,8 @@ rmw_create_service(
reinterpret_cast<void **>(&request_datareader),
reinterpret_cast<void **>(&response_datawriter),
&rmw_allocate);
DDS_String_free(service_str);
service_str = nullptr;
if (!replier) {
RMW_SET_ERROR_MSG("failed to create replier");
goto fail;
Expand Down Expand Up @@ -164,16 +167,26 @@ rmw_create_service(

// we have to set the partition array to length 1
// and then set the partition_str in it
if (request_partition_str && strlen(request_partition_str) != 0) {
subscriber_qos.partition.name.ensure_length(1, 1);
subscriber_qos.partition.name[0] = request_partition_str;
if (request_partition_str) {
if (strlen(request_partition_str) != 0) {
subscriber_qos.partition.name.ensure_length(1, 1);
// passing ownership to Connext
subscriber_qos.partition.name[0] = request_partition_str;
} else {
DDS_String_free(request_partition_str);
}
}
// update attached subscriber
dds_subscriber->set_qos(subscriber_qos);

if (response_partition_str && strlen(response_partition_str) != 0) {
publisher_qos.partition.name.ensure_length(1, 1);
publisher_qos.partition.name[0] = response_partition_str;
if (response_partition_str) {
if (strlen(response_partition_str) != 0) {
publisher_qos.partition.name.ensure_length(1, 1);
// passing ownership to Connext
publisher_qos.partition.name[0] = response_partition_str;
} else {
DDS_String_free(response_partition_str);
}
}
// update attached publisher
dds_publisher->set_qos(publisher_qos);
Expand Down Expand Up @@ -236,6 +249,14 @@ rmw_create_service(

return service;
fail:
if (request_partition_str) {
DDS_String_free(request_partition_str);
request_partition_str = nullptr;
}
if (response_partition_str) {
DDS_String_free(response_partition_str);
response_partition_str = nullptr;
}
if (service) {
rmw_service_free(service);
}
Expand Down

0 comments on commit 188147a

Please sign in to comment.