From 8bb41f5073d8dd51d483ed302b258fafefdb1511 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:44:03 -0800 Subject: [PATCH] fix: check the context validity before accessing the session (#403) (#407) (cherry picked from commit 660b1b0ab29797aab9f10ce99b40ad500e2c3106) Co-authored-by: Yuyuan Yuan --- rmw_zenoh_cpp/src/rmw_zenoh.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index 2e888cbc..98b842e9 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -388,6 +388,10 @@ rmw_create_publisher( context_impl, "unable to get rmw_context_impl_s", return nullptr); + if (context_impl->is_shutdown()) { + RMW_SET_ERROR_MSG("context_impl is shutdown"); + return nullptr; + } if (!context_impl->session_is_valid()) { RMW_SET_ERROR_MSG("zenoh session is invalid"); return nullptr; @@ -876,6 +880,10 @@ rmw_create_subscription( context_impl, "unable to get rmw_context_impl_s", return nullptr); + if (context_impl->is_shutdown()) { + RMW_SET_ERROR_MSG("context_impl is shutdown"); + return nullptr; + } if (!context_impl->session_is_valid()) { RMW_SET_ERROR_MSG("zenoh session is invalid"); return nullptr; @@ -1348,6 +1356,10 @@ rmw_create_client( context_impl, "unable to get rmw_context_impl_s", return nullptr); + if (context_impl->is_shutdown()) { + RMW_SET_ERROR_MSG("context_impl is shutdown"); + return nullptr; + } if (!context_impl->session_is_valid()) { RMW_SET_ERROR_MSG("zenoh session is invalid"); return nullptr; @@ -1596,6 +1608,10 @@ rmw_create_service( context_impl, "unable to get rmw_context_impl_s", return nullptr); + if (context_impl->is_shutdown()) { + RMW_SET_ERROR_MSG("context_impl is shutdown"); + return nullptr; + } if (!context_impl->session_is_valid()) { RMW_SET_ERROR_MSG("zenoh session is invalid"); return nullptr;