Skip to content

Commit 115373b

Browse files
Mauro PasserinoAlberto Soragna
authored andcommitted
Check for not valid msg on dispatch
1 parent 47fd21c commit 115373b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

rclcpp/include/rclcpp/any_subscription_callback.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ class AnySubscriptionCallback
185185
ConstMessageSharedPtr message, const rclcpp::MessageInfo & message_info)
186186
{
187187
TRACEPOINT(callback_start, (const void *)this, true);
188+
189+
// If the message is not valid, return.
190+
if(!message) {
191+
return;
192+
}
193+
188194
if (const_shared_ptr_callback_) {
189195
const_shared_ptr_callback_(message);
190196
} else if (const_shared_ptr_with_info_callback_) {
@@ -208,6 +214,12 @@ class AnySubscriptionCallback
208214
MessageUniquePtr message, const rclcpp::MessageInfo & message_info)
209215
{
210216
TRACEPOINT(callback_start, (const void *)this, true);
217+
218+
// If the message is not valid, return.
219+
if(!message) {
220+
return;
221+
}
222+
211223
if (shared_ptr_callback_) {
212224
typename std::shared_ptr<MessageT> shared_message = std::move(message);
213225
shared_ptr_callback_(shared_message);

rclcpp/include/rclcpp/experimental/subscription_intra_process.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ class SubscriptionIntraProcess : public SubscriptionIntraProcessBase
159159

160160
if (any_callback_.use_take_shared_method()) {
161161
ConstMessageSharedPtr msg = buffer_->consume_shared();
162-
if(msg != nullptr) {
163-
any_callback_.dispatch_intra_process(msg, msg_info);
164-
}
162+
any_callback_.dispatch_intra_process(msg, msg_info);
165163
} else {
166164
MessageUniquePtr msg = buffer_->consume_unique();
167165
any_callback_.dispatch_intra_process(std::move(msg), msg_info);

0 commit comments

Comments
 (0)