From 1ec021522671a4328c7ee6b63f944acebf8a2294 Mon Sep 17 00:00:00 2001 From: Maschell Date: Wed, 18 Feb 2026 15:37:20 +0100 Subject: [PATCH] Check for leaked memory when unloading a plugin --- source/main.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/main.cpp b/source/main.cpp index e9ca91a..38f4236 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -388,6 +388,21 @@ void CleanupPlugins(std::vector &pluginsToDeinit) { } plugin.DeinitButtonComboData(); } + + // Check for leaked memory + for (auto &plugin : pluginsToDeinit) { + if (const auto tracking = plugin.getTrackingMemoryAllocator()) { + if (const auto stats = tracking->GetHeapMemoryUsageSnapshot()) { + DEBUG_FUNCTION_LINE_WARN("Plugin \"%s\" leaked %d allocations", plugin.getMetaInformation().getName().c_str(), stats->allocationMap.size()); + for (const auto &alloc : stats->allocationMap) { + DEBUG_FUNCTION_LINE_WARN("Leaked %d bytes @ %p", alloc.second.size, alloc.first); + if (!alloc.second.stackTrace.empty()) { + PrintCapturedStackTrace(alloc.second.stackTrace); + } + } + } + } + } } void CheckCleanupCallbackUsage(const std::vector &plugins) { auto *curThread = OSGetCurrentThread();