From 60a6f2a733881498d52d0bf1b839b9a81faa54a3 Mon Sep 17 00:00:00 2001 From: AlexPeshkoff Date: Wed, 14 Aug 2024 16:57:20 +0300 Subject: [PATCH] Fixed UB caused by 0f8e7c18 - avoid storing dangling pointer to lambda --- src/common/classes/auto.h | 20 +++++++++++++++++++- src/common/classes/init.cpp | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/common/classes/auto.h b/src/common/classes/auto.h index 62fa4317dd..1bc0c32e08 100644 --- a/src/common/classes/auto.h +++ b/src/common/classes/auto.h @@ -331,7 +331,25 @@ public: } private: - F& clean; + F clean; +}; + +class CleanupFunction +{ + typedef void Func(); + +public: + CleanupFunction(Func* clFunc) + : clean(clFunc) + { } + + ~CleanupFunction() + { + clean(); + } + +private: + Func* clean; }; } //namespace Firebird diff --git a/src/common/classes/init.cpp b/src/common/classes/init.cpp index ce1ae272f1..89d71d65eb 100644 --- a/src/common/classes/init.cpp +++ b/src/common/classes/init.cpp @@ -145,7 +145,7 @@ namespace #ifndef DEBUG_INIT // This instance ensures dtors run when program exits - Firebird::Cleanup global(allClean); + Firebird::CleanupFunction global(allClean); #endif //DEBUG_INIT