From d3cdcb52d218a163d24be3f5a7d63e454b177873 Mon Sep 17 00:00:00 2001 From: "Marco Antonio J. Costa" Date: Fri, 31 Jul 2026 14:23:34 -0300 Subject: [PATCH] give the VFS log adapter static storage sgp.cpp held two of these. One was a file-scope vfs::FileLogger* that was never assigned, whose only other mention was a delete in shutdown that could therefore never fire; it goes. The other is the adapter VFS actually logs through, which was a bare new that nothing freed. Make that one a function-local static rather than a scoped object. VFS keeps the bare pointer and still logs from the shutdown that atexit runs after WinMain has returned, so the adapter has to outlive the frame it is declared in. Constructing it before InitializeStandardGamingPlatform registers that handler is what puts its destructor after the handler rather than before it. Co-Authored-By: Claude Opus 5 --- sgp/sgp.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sgp/sgp.cpp b/sgp/sgp.cpp index 27d07da94..f47dd0e34 100644 --- a/sgp/sgp.cpp +++ b/sgp/sgp.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include "sgp_logger.h" #include "Text.h" #include "ExportStrings.h" @@ -52,7 +51,6 @@ static std::list vfs_config_ini; static bool s_DebugKeyboardInput = false; static vfs::Path s_CodePage; -static vfs::FileLogger *vfslog = NULL; int iWindowedMode; @@ -610,7 +608,6 @@ void ShutdownStandardGamingPlatform(void) sgp::Logger::instance().shutdown(); vfs::Log::flushDeleteAll(); - if(vfslog) delete vfslog; vfs::CVirtualFileSystem::shutdownVFS(); vfs::ObjectAllocator::clear(); } @@ -742,9 +739,13 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCommandL sgp::Logger::instance().connectFile(VFS_LOG, L"vfs.log", false, sgp::Logger::FLUSH_ON_DELETE); - VfsLogAdapter* vfslog = new VfsLogAdapter(VFS_LOG); + // Static, not a scoped object: VFS keeps the bare pointer and still logs from + // the shutdown that atexit runs after WinMain has returned. Constructed here, + // before InitializeStandardGamingPlatform registers that handler, so it is + // destroyed after the handler has run rather than before it. + static VfsLogAdapter vfslog(VFS_LOG); - vfs::Aspects::setLogger(vfslog, vfslog, vfslog, NULL /* vfslog */); + vfs::Aspects::setLogger(&vfslog, &vfslog, &vfslog, NULL /* &vfslog */); // Make sure that only one instance of this application is running at once // // Look for prev instance by searching for the window