Skip to content

Commit 841ac41

Browse files
committed
fix: fix use-after-free bug in config reparse
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. 验证内存管理是否正确处理
1 parent 644f4ed commit 841ac41

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

dconfig-center/dde-dconfig-daemon/dconfigresource.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ bool DSGConfigResource::reparse(const QString &appid)
161161
}
162162

163163
// config refresh.
164-
delete file;
165-
file = nullptr;
164+
std::unique_ptr<DConfigFile> oldConfig(file);
166165
m_files[resouceKey] = config.release();
167166

168167
// emit valuechanged.

0 commit comments

Comments
 (0)