From 4d0be32e6c455edbf708003dffb67b11d512c5a6 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 8 Jan 2024 21:08:07 +0100 Subject: [PATCH] Capture `std::bad_alloc` on deserializeROSmessage. (#665) * Capture bad_alloc on deserializeROSmessage. Signed-off-by: Miguel Company --- rmw_fastrtps_cpp/src/type_support_common.cpp | 5 +++++ .../include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/rmw_fastrtps_cpp/src/type_support_common.cpp b/rmw_fastrtps_cpp/src/type_support_common.cpp index 4e5dff1dc..eb3d38232 100644 --- a/rmw_fastrtps_cpp/src/type_support_common.cpp +++ b/rmw_fastrtps_cpp/src/type_support_common.cpp @@ -119,6 +119,11 @@ bool TypeSupport::deserializeROSmessage( "Fast CDR exception deserializing message of type %s.", getName()); return false; + } catch (const std::bad_alloc &) { + RMW_SET_ERROR_MSG_WITH_FORMAT_STRING( + "'Bad alloc' exception deserializing message of type %s.", + getName()); + return false; } return true; diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp index f673fe073..899119f88 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp @@ -983,6 +983,11 @@ bool TypeSupport::deserializeROSmessage( "Fast CDR exception deserializing message of type %s.", getName()); return false; + } catch (const std::bad_alloc &) { + RMW_SET_ERROR_MSG_WITH_FORMAT_STRING( + "'Bad alloc' exception deserializing message of type %s.", + getName()); + return false; } return true;