Skip to content

Commit

Permalink
Copy topic name before deleting subscription.
Browse files Browse the repository at this point in the history
This fixes undefined behaviour, as the
rcl_subscription_get_topic_name documentation
states that the topic is no longer valid when
the subscription dies
  • Loading branch information
tobiasstarkwayve committed Oct 8, 2024
1 parent 89cec03 commit e0b6f91
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions r2r/src/subscribers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ where
drop(Box::from_raw(handle_ptr));
} else {
let topic_str = rcl_subscription_get_topic_name(handle_ptr);
let topic = CStr::from_ptr(topic_str);
let topic = CStr::from_ptr(topic_str).to_str().expect("to_str() call failed").to_owned();
drop(Box::from_raw(handle_ptr));

let err_str = rcutils_get_error_string();
Expand All @@ -118,7 +118,7 @@ where
panic!(
"rcl_return_loaned_message_from_subscription() \
failed for subscription on topic {}: {}",
topic.to_str().expect("to_str() call failed"),
topic,
error_msg.to_str().expect("to_str() call failed")
);
}
Expand Down

0 comments on commit e0b6f91

Please sign in to comment.