From 83929763fbfcd34afc6df26f82a8248549cd3cd6 Mon Sep 17 00:00:00 2001 From: Tim Spain Date: Tue, 1 Oct 2024 13:47:32 +0200 Subject: [PATCH] Fix the uniqueness detection in the finalizer even further. --- core/src/Finalizer.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/src/Finalizer.cpp b/core/src/Finalizer.cpp index 4698555cf..aadf929d7 100644 --- a/core/src/Finalizer.cpp +++ b/core/src/Finalizer.cpp @@ -27,8 +27,8 @@ bool Finalizer::contains(const FinalFn& fn) { auto& fns = functions(); for (const auto& stored : fns) { - // Compare function pointer addresses - if (stored.target() == fn.target()) + // Compare function addresses + if (*stored.target() == *fn.target()) return true; } return false; @@ -37,8 +37,14 @@ bool Finalizer::contains(const FinalFn& fn) void Finalizer::finalize() { while (!functions().empty()) { - // Execute the last function in the list - functions().back()(); + try { + // Execute the last function in the list + functions().back()(); + } catch (const std::exception& e) { + // Remove the function from the finalization list even if an exception was thrown. + functions().pop_back(); + throw; + } // Remove the function from the finalization list. functions().pop_back(); }