From 3e34c03c5d43ae9285f209426dfad6cf1a8c1fbb Mon Sep 17 00:00:00 2001 From: yeshanshan Date: Tue, 9 Sep 2025 21:15:52 +0800 Subject: [PATCH] fix: fix use-after-free bug in config reparse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed a use-after-free bug where the file pointer was being deleted before being reassigned, which could lead to dangling pointer issues. Replaced manual deletion with std::unique_ptr to ensure proper ownership transfer and automatic cleanup. Influence: 1. Test config file reloading functionality 2. Verify no crashes occur during config refresh operations 3. Test multiple consecutive config reparse operations 4. Verify memory management is handled correctly fix: 修复配置重新解析中的释放后使用错误 修复了一个释放后使用的错误,其中文件指针在重新分配之前被删除,可能导致悬 空指针问题。使用 std::unique_ptr 替换手动删除操作,确保正确的所有权转移 和自动清理。 Influence: 1. 测试配置文件重新加载功能 2. 验证配置刷新操作期间不会发生崩溃 3. 测试多次连续的配置重新解析操作 4. 验证内存管理是否正确处理 --- dconfig-center/dde-dconfig-daemon/dconfigresource.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dconfig-center/dde-dconfig-daemon/dconfigresource.cpp b/dconfig-center/dde-dconfig-daemon/dconfigresource.cpp index e9f31d4..6295747 100644 --- a/dconfig-center/dde-dconfig-daemon/dconfigresource.cpp +++ b/dconfig-center/dde-dconfig-daemon/dconfigresource.cpp @@ -161,8 +161,7 @@ bool DSGConfigResource::reparse(const QString &appid) } // config refresh. - delete file; - file = nullptr; + std::unique_ptr oldConfig(file); m_files[resouceKey] = config.release(); // emit valuechanged.