Skip to content

Commit

Permalink
Improve error checking and handling in subscription APIs. (#739)
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic authored and ahcorde committed Oct 23, 2020
1 parent a270de6 commit 7cc97f4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions rcl/src/rcl/subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ rcl_subscription_init(
}

allocator->deallocate(subscription->impl, allocator->state);
subscription->impl = NULL;
}
ret = fail_ret;
// Fall through to cleanup
Expand Down Expand Up @@ -238,6 +239,7 @@ rcl_subscription_fini(rcl_subscription_t * subscription, rcl_node_t * node)
result = RCL_RET_ERROR;
}
allocator.deallocate(subscription->impl, allocator.state);
subscription->impl = NULL;
}
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Subscription finalized");
return result;
Expand Down Expand Up @@ -301,10 +303,6 @@ rcl_take_sequence(
rmw_subscription_allocation_t * allocation
)
{
// Set the sizes to zero to indicate that there are no valid messages
message_sequence->size = 0u;
message_info_sequence->size = 0u;

RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Subscription taking %zu messages", count);
if (!rcl_subscription_is_valid(subscription)) {
return RCL_RET_SUBSCRIPTION_INVALID; // error message already set
Expand All @@ -322,6 +320,10 @@ rcl_take_sequence(
return RCL_RET_INVALID_ARGUMENT;
}

// Set the sizes to zero to indicate that there are no valid messages
message_sequence->size = 0u;
message_info_sequence->size = 0u;

size_t taken = 0u;
rmw_ret_t ret = rmw_take_sequence(
subscription->impl->rmw_handle, count, message_sequence, message_info_sequence, &taken,
Expand Down Expand Up @@ -385,6 +387,7 @@ rcl_take_loaned_message(
if (!rcl_subscription_is_valid(subscription)) {
return RCL_RET_SUBSCRIPTION_INVALID; // error already set
}
RCL_CHECK_ARGUMENT_FOR_NULL(loaned_message, RCL_RET_INVALID_ARGUMENT);
if (*loaned_message) {
RCL_SET_ERROR_MSG("loaned message is already initialized");
return RCL_RET_INVALID_ARGUMENT;
Expand Down

0 comments on commit 7cc97f4

Please sign in to comment.