Skip to content

Commit

Permalink
spdlog: do not drop logger in destructor
Browse files Browse the repository at this point in the history
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: ros2/rclcpp#933
Link: gabime/spdlog#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 <peter.colberg@intel.com>
  • Loading branch information
pcolberg committed Apr 8, 2024
1 parent b96e35c commit e874ea6
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 5 deletions.
2 changes: 0 additions & 2 deletions libraries/afu-test/afu_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }
Expand Down
1 change: 0 additions & 1 deletion samples/cxl_hello_fpga/he_cache_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ class afu {
}
virtual ~afu() {
if (fd_ > 0) close(fd_);
if (logger_) spdlog::drop(logger_->name());
}

CLI::App &cli() { return app_; }
Expand Down
2 changes: 0 additions & 2 deletions samples/cxl_host_exerciser/he_cache_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ class afu {

if (fd_ > 0)
close(fd_);
if (logger_)
spdlog::drop(logger_->name());
}

CLI::App &cli() { return app_; }
Expand Down

0 comments on commit e874ea6

Please sign in to comment.