From af75dce660c9eaf743839df346a7eb0f9c69b08c Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Sat, 10 May 2025 09:59:13 +1200 Subject: [PATCH] Fix Crashes with GCC 15 #5088 When building `WITH_PYTHON`, where a global list of modules is maintained, deleting a module also erases the entry in said global list. This can lead to memory corruption if the global list is destructed before the module. Using `on_shutdown()` instead means the module destructor is explicitly called before the global list can be destructed, preventing the issue. Also add a comment to `Pass::~Pass()` to suggest the same for future passes that might try to use that (and see this commit in the blame if they need a reason why). --- kernel/register.h | 1 + passes/cmds/design.cc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/register.h b/kernel/register.h index 25ea9f232..f4e2127e1 100644 --- a/kernel/register.h +++ b/kernel/register.h @@ -29,6 +29,7 @@ struct Pass { std::string pass_name, short_help; Pass(std::string name, std::string short_help = "** document me **"); + // Prefer overriding 'Pass::on_shutdown()' if possible virtual ~Pass(); virtual void help(); diff --git a/passes/cmds/design.cc b/passes/cmds/design.cc index efc72dfb7..a2ae45ef3 100644 --- a/passes/cmds/design.cc +++ b/passes/cmds/design.cc @@ -28,7 +28,7 @@ std::vector pushed_designs; struct DesignPass : public Pass { DesignPass() : Pass("design", "save, restore and reset current design") { } - ~DesignPass() override { + void on_shutdown() override { for (auto &it : saved_designs) delete it.second; saved_designs.clear();