From be2cf37c9c8a3ca72381ffbdf22a820ceb69fc66 Mon Sep 17 00:00:00 2001 From: Miaofei Date: Tue, 10 Dec 2019 16:25:01 -0800 Subject: [PATCH] fix error handling in _handle_topic_info_fini() Signed-off-by: Miaofei Mei --- .../src/rmw_get_topic_info.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/src/rmw_get_topic_info.cpp b/rmw_fastrtps_shared_cpp/src/rmw_get_topic_info.cpp index 93d7c9571..e9354de9d 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_get_topic_info.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_get_topic_info.cpp @@ -93,12 +93,23 @@ _handle_topic_info_fini( rmw_topic_info_t * topic_info, rcutils_allocator_t * allocator) { - std::string error_string = rmw_get_error_string().str; + bool had_error = rmw_error_is_set(); + std::string error_string; + if (had_error) { + error_string = rmw_get_error_string().str; + } rmw_reset_error(); + rmw_ret_t ret = rmw_topic_info_fini(topic_info, allocator); if (ret != RMW_RET_OK) { - error_string += rmw_get_error_string().str; + RCUTILS_LOG_ERROR_NAMED( + "rmw_fastrtps_cpp", + "rmw_topic_info_fini failed: %s", + rmw_get_error_string().str); rmw_reset_error(); + } + + if (had_error) { RMW_SET_ERROR_MSG(error_string.c_str()); } } @@ -245,7 +256,7 @@ _get_info_by_topic( for (auto & tinfo : topic_info_vector) { _handle_topic_info_fini(&tinfo, allocator); } - return RMW_RET_BAD_ALLOC; + return ret; } for (auto i = 0u; i < count; i++) { participants_info->info_array[i] = topic_info_vector.at(i);