fix: prevent crash when destroying QWidget during XIO error#1474
fix: prevent crash when destroying QWidget during XIO error#1474deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Conversation
There was a problem hiding this comment.
Sorry @18202781743, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, BLumia The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Added destructor to X11WindowMonitor to safely handle window preview destruction during XIO error conditions. Changed m_windowPreview from QScopedPointer to std::unique_ptr to enable manual release and deleteLater() call. Updated all null checks from isNull() to boolean checks for consistency with smart pointer usage. When XIO errors occur during X11 session termination, directly deleting QWidget objects that access OpenGL can cause crashes. The destructor now releases the unique_ptr and uses deleteLater() to schedule deletion in a safer context. This prevents immediate destruction during XIO error cleanup. Log: Fixed crash when closing application during XIO errors Influence: 1. Test application termination during XIO error conditions 2. Verify window preview functionality still works normally 3. Check memory management during session termination 4. Test with multiple window previews and rapid open/close cycles 5. Verify no resource leaks during normal operation fix: 修复XIO异常退出时析构QWidget访问OpenGL导致的崩溃问题 为X11WindowMonitor添加析构函数,以安全处理XIO错误条件下的窗口预览析构。 将m_windowPreview从QScopedPointer改为std::unique_ptr,以便手动释放并调用 deleteLater()。更新所有空值检查,从isNull()改为布尔检查,以保持与智能指 针使用的一致性。 当X11会话终止期间发生XIO错误时,直接删除访问OpenGL的QWidget对象可能导致 崩溃。析构函数现在释放unique_ptr并使用deleteLater()在更安全的上下文中安 排删除。这防止了在XIO错误清理期间立即析构。 Log: 修复了在XIO错误时关闭应用程序导致的崩溃问题 Influence: 1. 测试XIO错误条件下的应用程序终止 2. 验证窗口预览功能在正常情况下仍正常工作 3. 检查会话终止期间的内存管理 4. 测试多个窗口预览和快速打开/关闭循环 5. 验证正常操作期间没有资源泄漏 PMS: BUG-350887
deepin pr auto reviewGit Diff 代码审查报告我已对提供的 Git Diff 进行了详细审查,以下是我的分析和建议: 整体评估这次更改主要是将 具体审查意见1. 语法逻辑优点:
问题:
2. 代码质量优点:
问题:
3. 代码性能优点:
问题:
4. 代码安全优点:
问题:
改进建议
if (!m_windowPreview) {
if (!relativePositionItem) {
qWarning() << "Invalid relativePositionItem for preview window";
return;
}
m_windowPreview.reset(new X11WindowPreviewContainer(this));
m_windowPreview->setMaskAlpha(static_cast<int>(m_opacity * 255));
m_windowPreview->windowHandle()->setTransientParent(relativePositionItem);
}
void X11WindowMonitor::setPreviewOpacity(double opacity)
{
m_opacity = qBound(0.0, opacity, 1.0); // 确保值在0-1范围内
if (m_windowPreview) {
m_windowPreview->setMaskAlpha(static_cast<int>(m_opacity * 255));
}
}
m_windowPreview = std::make_unique<X11WindowPreviewContainer>(this);
X11WindowMonitor::~X11WindowMonitor()
{
// 不要直接删除预览窗口,因为在 XIO 错误情况下删除 QWidget 可能导致崩溃。
// 使用 deleteLater() 可以确保在事件循环中安全地删除对象。
if (auto preview = m_windowPreview.release()) {
preview->deleteLater();
}
}
总结这次更改总体上是积极的,主要是将 Qt 特有的智能指针替换为 C++ 标准库中的智能指针,并添加了析构函数来安全地释放资源。建议按照上述改进建议进行一些小的修改,以提高代码的健壮性和可维护性。 |
|
/forcemerge |
1 similar comment
|
/forcemerge |
|
This pr force merged! (status: unstable) |
|
This pr force merged! (status: unknown) |
Added destructor to X11WindowMonitor to safely handle window preview
destruction during XIO error conditions. Changed m_windowPreview
from QScopedPointer to std::unique_ptr to enable manual release and
deleteLater() call. Updated all null checks from isNull() to boolean
checks for consistency with smart pointer usage.
When XIO errors occur during X11 session termination, directly deleting
QWidget objects that access OpenGL can cause crashes. The destructor now
releases the unique_ptr and uses deleteLater() to schedule deletion in
a safer context. This prevents immediate destruction during XIO error
cleanup.
Log: Fixed crash when closing application during XIO errors
Influence:
fix: 修复XIO异常退出时析构QWidget访问OpenGL导致的崩溃问题
为X11WindowMonitor添加析构函数,以安全处理XIO错误条件下的窗口预览析构。
将m_windowPreview从QScopedPointer改为std::unique_ptr,以便手动释放并调用
deleteLater()。更新所有空值检查,从isNull()改为布尔检查,以保持与智能指
针使用的一致性。
当X11会话终止期间发生XIO错误时,直接删除访问OpenGL的QWidget对象可能导致
崩溃。析构函数现在释放unique_ptr并使用deleteLater()在更安全的上下文中安
排删除。这防止了在XIO错误清理期间立即析构。
Log: 修复了在XIO错误时关闭应用程序导致的崩溃问题
Influence:
PMS: BUG-350887