From 199a26984df3f1bb4d2cd1d00695e41a1358e592 Mon Sep 17 00:00:00 2001 From: Ethan Gao <16472154+gaoethan@users.noreply.github.com> Date: Wed, 20 Dec 2017 05:39:56 +0800 Subject: [PATCH] Fix the potential application crash issues (#426) * err msg * err msg * Fix the potential application crash issues Signed-off-by: Ethan Gao * minor tweak the code structure Signed-off-by: Ethan Gao --- rclcpp/include/rclcpp/service.hpp | 7 ++++++- rclcpp/src/rclcpp/publisher.cpp | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/rclcpp/include/rclcpp/service.hpp b/rclcpp/include/rclcpp/service.hpp index c84f3be..79038ac 100644 --- a/rclcpp/include/rclcpp/service.hpp +++ b/rclcpp/include/rclcpp/service.hpp @@ -158,8 +158,13 @@ public: std::string("rcl_service_t in constructor argument must be initialized beforehand.")); // *INDENT-ON* } + + const char * service_name = rcl_service_get_service_name(service_handle); + if (!service_name) { + throw std::runtime_error("failed to get service name"); + } service_handle_ = service_handle; - service_name_ = std::string(rcl_service_get_service_name(service_handle)); + service_name_ = std::string(service_name); owns_rcl_handle_ = false; } diff --git a/rclcpp/src/rclcpp/publisher.cpp b/rclcpp/src/rclcpp/publisher.cpp index 5a488d1..406f927 100644 --- a/rclcpp/src/rclcpp/publisher.cpp +++ b/rclcpp/src/rclcpp/publisher.cpp @@ -170,7 +170,13 @@ PublisherBase::setup_intra_process( StoreMessageCallbackT callback, const rcl_publisher_options_t & intra_process_options) { - auto intra_process_topic_name = std::string(this->get_topic_name()) + "/_intra"; + const char * topic_name = this->get_topic_name(); + if (!topic_name) { + throw std::runtime_error("failed to get topic name"); + } + + auto intra_process_topic_name = std::string(topic_name) + "/_intra"; + rcl_ret_t ret = rcl_publisher_init( &intra_process_publisher_handle_, rcl_node_handle_.get(),