From 508a944f964f3fea9c527af39a348d9c39dd23b8 Mon Sep 17 00:00:00 2001 From: "xinyu.wang" Date: Wed, 4 Sep 2024 21:49:15 +0200 Subject: [PATCH 1/3] suppress leak sanitizer for expected leak --- rmw_cyclonedds_cpp/src/rmw_node.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rmw_cyclonedds_cpp/src/rmw_node.cpp b/rmw_cyclonedds_cpp/src/rmw_node.cpp index af6411010..a1fc4c1ff 100644 --- a/rmw_cyclonedds_cpp/src/rmw_node.cpp +++ b/rmw_cyclonedds_cpp/src/rmw_node.cpp @@ -191,6 +191,15 @@ struct Cdds {} }; +#if defined(__has_feature) +#if __has_feature(address_sanitizer) // for clang +#define __SANITIZE_ADDRESS__ // GCC already sets this +#endif +#endif + +#if defined(__SANITIZE_ADDRESS__) +#include +#endif /* Use construct-on-first-use for the global state rather than a plain global variable to prevent its destructor from running prior to last use by some other component in the system. E.g., some rclcpp tests (at the time of this commit) drop a guard condition in @@ -209,6 +218,9 @@ struct Cdds static Cdds & gcdds() { static Cdds * x = new Cdds(); +#if defined(__SANITIZE_ADDRESS__) + __lsan_ignore_object(x); +#endif return *x; } From 6b3fee707381ee66f0fcf3ea7b9b0ffd96b62b1c Mon Sep 17 00:00:00 2001 From: comicfans Date: Thu, 5 Sep 2024 11:42:50 +0200 Subject: [PATCH 2/3] Update rmw_node.cpp fix lint Signed-off-by: comicfans --- rmw_cyclonedds_cpp/src/rmw_node.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rmw_cyclonedds_cpp/src/rmw_node.cpp b/rmw_cyclonedds_cpp/src/rmw_node.cpp index a1fc4c1ff..f3594226f 100644 --- a/rmw_cyclonedds_cpp/src/rmw_node.cpp +++ b/rmw_cyclonedds_cpp/src/rmw_node.cpp @@ -200,6 +200,8 @@ struct Cdds #if defined(__SANITIZE_ADDRESS__) #include #endif + + /* Use construct-on-first-use for the global state rather than a plain global variable to prevent its destructor from running prior to last use by some other component in the system. E.g., some rclcpp tests (at the time of this commit) drop a guard condition in From 8d8874de227dd16deb58331e4879ac7f883d736c Mon Sep 17 00:00:00 2001 From: comicfans Date: Thu, 5 Sep 2024 19:27:05 +0200 Subject: [PATCH 3/3] Update rmw_node.cpp linter fix Signed-off-by: comicfans --- rmw_cyclonedds_cpp/src/rmw_node.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rmw_cyclonedds_cpp/src/rmw_node.cpp b/rmw_cyclonedds_cpp/src/rmw_node.cpp index f3594226f..83bd1928b 100644 --- a/rmw_cyclonedds_cpp/src/rmw_node.cpp +++ b/rmw_cyclonedds_cpp/src/rmw_node.cpp @@ -192,8 +192,8 @@ struct Cdds }; #if defined(__has_feature) -#if __has_feature(address_sanitizer) // for clang -#define __SANITIZE_ADDRESS__ // GCC already sets this +#if __has_feature(address_sanitizer) // for clang +#define __SANITIZE_ADDRESS__ // GCC already sets this #endif #endif