From 993f3a26e52c7d7ffb27a93dc766fa197abb711d Mon Sep 17 00:00:00 2001 From: yeshanshan Date: Wed, 11 Feb 2026 16:38:42 +0800 Subject: [PATCH] fix: prevent crash during static destruction of DPluginLoader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Modified DPluginLoader destructor to check Qt application state before calling destroy() 2. Added condition to only call destroy() when qApp exists and application is not closing down 3. Added warning message when skipping destruction to avoid crash during static cleanup 4. This prevents crashes when DPluginLoader is destroyed after Qt global resources have been cleaned up Log: Fixed potential crash during application shutdown when using static plugin loader Influence: 1. Test application shutdown process with static plugin loader 2. Verify no crashes occur during normal application exit 3. Test edge cases where Qt resources might be cleaned up early 4. Monitor for warning messages about skipped destruction during abnormal shutdown 5. Verify memory cleanup still occurs properly during normal shutdown fix: 防止 DPluginLoader 静态析构时崩溃 1. 修改 DPluginLoader 析构函数,在调用 destroy() 前检查 Qt 应用程序状态 2. 添加条件判断,仅当 qApp 存在且应用程序未关闭时才调用 destroy() 3. 添加警告信息,当跳过析构以避免静态清理期间的崩溃时进行提示 4. 防止在 Qt 全局资源已清理后销毁 DPluginLoader 时发生崩溃 Log: 修复使用静态插件加载器时应用程序关闭可能崩溃的问题 Influence: 1. 测试使用静态插件加载器时的应用程序关闭过程 2. 验证正常应用程序退出时不会发生崩溃 3. 测试 Qt 资源可能提前清理的边缘情况 4. 监控异常关闭期间关于跳过析构的警告信息 5. 验证正常关闭期间内存清理仍能正确进行 PMS: BUG-350887 --- frame/pluginloader.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/frame/pluginloader.cpp b/frame/pluginloader.cpp index ddde01479..01ab0bd31 100644 --- a/frame/pluginloader.cpp +++ b/frame/pluginloader.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -229,7 +229,17 @@ DPluginLoader::DPluginLoader() DPluginLoader::~DPluginLoader() { - destroy(); + // 防止在 Qt 全局资源清理后析构导致崩溃 + // 当作为 Q_APPLICATION_STATIC 静态对象时,析构可能发生在 Qt 全局资源清理之后 + // 此时子 Applet 的析构可能访问已清理的 Qt 全局资源(如 QThreadStorage) + if (qApp && !QCoreApplication::closingDown()) { + // 正常情况:在 aboutToQuit 中调用的 destroy(),Qt 资源有效 + destroy(); + } else { + // 异常情况:静态析构阶段,Qt 全局资源可能已清理 + // 不调用 destroy(),避免触发子对象析构 + // 内存泄漏无关紧要,程序即将退出,操作系统会回收所有资源 + } } DPluginLoader *DPluginLoader::instance()