Skip to content

Commit 1c2bd84

Browse files
Avoid returning loan when none was obtained. (ros2#1629)
Signed-off-by: Miguel Company <[email protected]>
1 parent c4a68b4 commit 1c2bd84

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

rclcpp/src/rclcpp/executor.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -610,16 +610,18 @@ Executor::execute_subscription(rclcpp::SubscriptionBase::SharedPtr subscription)
610610
return true;
611611
},
612612
[&]() {subscription->handle_loaned_message(loaned_msg, message_info);});
613-
rcl_ret_t ret = rcl_return_loaned_message_from_subscription(
614-
subscription->get_subscription_handle().get(),
615-
loaned_msg);
616-
if (RCL_RET_OK != ret) {
617-
RCLCPP_ERROR(
618-
rclcpp::get_logger("rclcpp"),
619-
"rcl_return_loaned_message_from_subscription() failed for subscription on topic '%s': %s",
620-
subscription->get_topic_name(), rcl_get_error_string().str);
613+
if (nullptr != loaned_msg) {
614+
rcl_ret_t ret = rcl_return_loaned_message_from_subscription(
615+
subscription->get_subscription_handle().get(),
616+
loaned_msg);
617+
if (RCL_RET_OK != ret) {
618+
RCLCPP_ERROR(
619+
rclcpp::get_logger("rclcpp"),
620+
"rcl_return_loaned_message_from_subscription() failed for subscription on topic '%s': %s",
621+
subscription->get_topic_name(), rcl_get_error_string().str);
622+
}
623+
loaned_msg = nullptr;
621624
}
622-
loaned_msg = nullptr;
623625
} else {
624626
// This case is taking a copy of the message data from the middleware via
625627
// inter-process communication.

0 commit comments

Comments
 (0)