fix: eliminate remaining memory leaks in application-tray#457
Conversation
There was a problem hiding this comment.
Sorry @yixinshark, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
SNI icon handling: - Add m_cachedAttentionIcon / m_cachedOverlayIcon to cache attention and overlay icons, following the same pattern as m_cachedIcon, to avoid repeated D-Bus pixmap reads during attention state blinking - Skip icon pixmap updates on NewIcon / NewOverlayIcon / NewAttentionIcon signals when the client provides a theme icon name, since the getter already resolves icons from the icon theme in that case and the cached pixmap is not needed - Rework dbusImageList2QIcon: deep-copy the DBusImageList before modifying pixel data to fix const-cast undefined behavior with Qt6 QByteArray; use quint32* for correct type semantics and bounded iteration (size/4 instead of raw byte stride) XCB image lifecycle (XEmbed path): - Fix xcb_image_t leak in Util::convertFromNative when the pixel depth falls into the unsupported default case - Explicitly call xcb_image_destroy when QImage construction from xcb_image_t fails, since Qt's cleanup callback is not invoked in the null state - Replace QSharedPointer/QScopedPointer default delete deleters with explicit free() for xcb reply pointers allocated via malloc, fixing undefined behavior and potential leaks in both Util and XembedProtocolHandler - Refactor getX11WindowImageNonComposite to deep-copy the image data via QImage::copy and immediately destroy the xcb_image_t, bypassing Qt's unreliable cleanup callback that can be evaded by std::move and heuristic mask operations Build: - Fix debian/rules to export QT_SELECT=qt6 instead of qt5 since the tray plugin links against Qt6 Together with the corresponding DTK fix (QMetaType::destruct before construct in DDBusExtendedAbstractInterface::internalPropGet), this reduces application-tray RSS growth from ~23 KB/s to negligible levels. SNI 图标处理: - 新增 m_cachedAttentionIcon / m_cachedOverlayIcon 缓存 attention/overlay 图标,沿用 m_cachedIcon 的缓存模式,避免闪烁状态期间每次 paint 重复走 DBus 属性读取 - NewIcon / NewOverlayIcon / NewAttentionIcon 信号处理中,当客户端提供 主题图标名时跳过 pixmap 更新,因为 getter 已经优先从图标主题加载 - 重写 dbusImageList2QIcon: 修改像素数据前显式深拷贝 DBusImageList, 修正 Qt6 QByteArray 的 const_cast 未定义行为;使用 quint32* 替代 qint32* 获得正确的类型语义,循环边界改为 size/4 XCB 图像生命周期: - convertFromNative 函数 default 分支中释放 xcb_image_t 防止泄漏 - QImage 从 xcb_image_t 构造失败时显式调用 xcb_image_destroy,弥补 Qt 在 null state 下不触发 cleanup callback 的问题 - QSharedPointer/QScopedPointer 使用 free 替代默认的 delete 释放 malloc 分配的 xcb reply 指针,修正未定义行为 - getX11WindowImageNonComposite 通过 QImage::copy 深拷贝后直接 xcb_image_destroy,绕过 Qt cleanup callback 被 std::move 和 heuristic mask 绕过的风险 构建: - debian/rules 修正 QT_SELECT=qt6,匹配实际 Qt6 链接 配合 DTK 修复(DDBusExtendedAbstractInterface::internalPropGet 中 construct 前添加 destruct),application-tray RSS 增长从约 23 KB/s 降至可忽略水平。 Log: fix: eliminate remaining memory leaks in application-tray Pms: BUG-359161
c3c668b to
e757a44
Compare
deepin pr auto review你好!我是你的智能编程助手 CodeGeeX。我已仔细审查了你提供的 Git Diff。 本次代码变更主要涉及将 Qt 版本从 Qt5 升级到 Qt6,对 SNI(StatusNotifierItem)托盘图标的缓存机制进行了优化,并修复了多处 X11/XCB 相关的严重内存泄漏和潜在的内存安全问题。 总体来说,这是一次质量很高的重构。以下我将从语法逻辑、代码质量、代码性能和代码安全四个维度为你提供详细的审查意见和改进建议: 一、 语法与逻辑
二、 代码质量
三、 代码性能
四、 代码安全
总结本次提交质量很高,解决了从 Qt5 迁移到 Qt6 过程中的核心内存管理问题,特别是 XCB 层面的内存泄漏和 建议修改点:
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: robertkill, yixinshark 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 |
SNI icon handling:
and overlay icons, following the same pattern as m_cachedIcon, to
avoid repeated D-Bus pixmap reads during attention state blinking
NewAttentionIcon signals when the client provides a theme icon name,
since the getter already resolves icons from the icon theme in that
case and the cached pixmap is not needed
modifying pixel data to fix const-cast undefined behavior with Qt6
QByteArray; use quint32* for correct type semantics and bounded
iteration (size/4 instead of raw byte stride)
XCB image lifecycle (XEmbed path):
falls into the unsupported default case
xcb_image_t fails, since Qt's cleanup callback is not invoked in the
null state
explicit free() for xcb reply pointers allocated via malloc, fixing
undefined behavior and potential leaks in both Util and
XembedProtocolHandler
via QImage::copy and immediately destroy the xcb_image_t, bypassing
Qt's unreliable cleanup callback that can be evaded by std::move and
heuristic mask operations
Build:
the tray plugin links against Qt6
Together with the corresponding DTK fix (QMetaType::destruct before
construct in DDBusExtendedAbstractInterface::internalPropGet), this
reduces application-tray RSS growth from ~23 KB/s to negligible levels.
SNI 图标处理:
图标,沿用 m_cachedIcon 的缓存模式,避免闪烁状态期间每次 paint
重复走 DBus 属性读取
主题图标名时跳过 pixmap 更新,因为 getter 已经优先从图标主题加载
修正 Qt6 QByteArray 的 const_cast 未定义行为;使用 quint32* 替代
qint32* 获得正确的类型语义,循环边界改为 size/4
XCB 图像生命周期:
Qt 在 null state 下不触发 cleanup callback 的问题
malloc 分配的 xcb reply 指针,修正未定义行为
xcb_image_destroy,绕过 Qt cleanup callback 被 std::move 和
heuristic mask 绕过的风险
构建:
配合 DTK 修复(DDBusExtendedAbstractInterface::internalPropGet 中
construct 前添加 destruct),application-tray RSS 增长从约 23 KB/s
降至可忽略水平。
Log: fix: eliminate remaining memory leaks in application-tray
Pms: BUG-359161