From e0b6f911ad0b6bea41ecf9c4cfd12fec6ca8dc69 Mon Sep 17 00:00:00 2001 From: Tobias Stark Date: Tue, 8 Oct 2024 12:51:47 +0000 Subject: [PATCH] Copy topic name before deleting subscription. This fixes undefined behaviour, as the rcl_subscription_get_topic_name documentation states that the topic is no longer valid when the subscription dies --- r2r/src/subscribers.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/r2r/src/subscribers.rs b/r2r/src/subscribers.rs index aff451083..5ee510209 100644 --- a/r2r/src/subscribers.rs +++ b/r2r/src/subscribers.rs @@ -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(); @@ -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") ); }