From e874ea6c42050561f04e3923215b9e4c704ac91e Mon Sep 17 00:00:00 2001 From: Peter Colberg Date: Mon, 8 Apr 2024 14:46:26 -0400 Subject: [PATCH] spdlog: do not drop logger in destructor For static objects, the order of destruction is in reverse of the order of construction, but the latter is hard to control except among static objects defined within the same translation unit. This means that spdlog may be destructed before spdlog::drop() is invoked in the destructor, which leads to a segmentation fault due to memory use-after-free. The spdlog example points out that dropping all loggers via spdlog::shutdown(), which invokes spdlog::drop_all(), is optional. Omit destructor calls of spdlog::drop(), but retain non-destructor calls of spdlog::drop_all() for now since they do not cause any harm. Link: https://github.com/ros2/rclcpp/issues/933 Link: https://github.com/gabime/spdlog/issues/1738 Link: https://github.com/gabime/spdlog/blob/a2b4262090fd3f005c2315dcb5be2f0f1774a005/example/example.cpp#L96 Closes: https://hsdes.intel.com/appstore/article/#/22019839238 Signed-off-by: Peter Colberg --- libraries/afu-test/afu_test.h | 2 -- samples/cxl_hello_fpga/he_cache_test.h | 1 - samples/cxl_host_exerciser/he_cache_test.h | 2 -- 3 files changed, 5 deletions(-) diff --git a/libraries/afu-test/afu_test.h b/libraries/afu-test/afu_test.h index 8a8f78496919..a045d1009ee4 100644 --- a/libraries/afu-test/afu_test.h +++ b/libraries/afu-test/afu_test.h @@ -186,8 +186,6 @@ class afu { app_.add_option("-t,--timeout", timeout_msec_, "test timeout (msec)")->default_str(std::to_string(timeout_msec_)); } virtual ~afu() { - if (logger_) - spdlog::drop(logger_->name()); } CLI::App & cli() { return app_; } diff --git a/samples/cxl_hello_fpga/he_cache_test.h b/samples/cxl_hello_fpga/he_cache_test.h index 52699c1b7891..2a61eaa00d71 100644 --- a/samples/cxl_hello_fpga/he_cache_test.h +++ b/samples/cxl_hello_fpga/he_cache_test.h @@ -297,7 +297,6 @@ class afu { } virtual ~afu() { if (fd_ > 0) close(fd_); - if (logger_) spdlog::drop(logger_->name()); } CLI::App &cli() { return app_; } diff --git a/samples/cxl_host_exerciser/he_cache_test.h b/samples/cxl_host_exerciser/he_cache_test.h index b737800a83a6..c5d3de580453 100644 --- a/samples/cxl_host_exerciser/he_cache_test.h +++ b/samples/cxl_host_exerciser/he_cache_test.h @@ -304,8 +304,6 @@ class afu { if (fd_ > 0) close(fd_); - if (logger_) - spdlog::drop(logger_->name()); } CLI::App &cli() { return app_; }