修复切换主题时分配QPalette的内存泄漏

This commit is contained in:
liuxinhao 2022-11-25 11:04:29 +08:00
parent 7b683f4d98
commit b81404d7e0
2 changed files with 69 additions and 1 deletions

View File

@ -0,0 +1,64 @@
From eae79d3e1836ed1aa31a92e32235f33515e4e584 Mon Sep 17 00:00:00 2001
From: liuxinhao <liuxinhao@kylinsec.com.cn>
Date: Tue, 8 Nov 2022 17:41:39 +0800
Subject: [PATCH] fix(Memory leak): Fix the memory leak
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
修复切换主题时分配QPalette的内存泄漏
---
platformtheme/kiran-theme.cpp | 8 ++++++++
style/src/render-helper.cpp | 3 ++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/platformtheme/kiran-theme.cpp b/platformtheme/kiran-theme.cpp
index 1955fc4..bf48006 100644
--- a/platformtheme/kiran-theme.cpp
+++ b/platformtheme/kiran-theme.cpp
@@ -335,6 +335,7 @@ void KiranTheme::handleThemeChanged()
{
// NOTE: SchemeLoader会接收KiranAppearanceMonitor的GTK主题改变信号重新加载配色方案
// 此处只需等到下一个事件循环通知QGuiApplication重新更新palette
+
// clang-format off
QTimer::singleShot(0, [this] {
// 此事件会促使QGuiApplication重新从QPlatformTheme中获取系统级别的QPalette
@@ -356,8 +357,15 @@ void KiranTheme::handleThemeChanged()
///FIXME:
///1.后续看是否有更好的方式能应用更新系统级别QPalette
///2.加入判断是否外部自定义设置Application palette若外部自定义设置了则应不做处理
+
+ QPalette* oldPalette = nullptr;
+ oldPalette = QGuiApplicationPrivate::app_pal;
+
QGuiApplicationPrivate::app_pal = new QPalette(*palette(SystemPalette));
+ if( oldPalette )
+ delete oldPalette;
+
// 该接口原本用于windows通知窗口主题变化时使用,现用来通知调用QGuiApplicationPrivate::notifyThemeChanged
QGuiApplicationPrivate::processThemeChanged(&event);
emit qApp->paletteChanged(*palette(SystemPalette));
diff --git a/style/src/render-helper.cpp b/style/src/render-helper.cpp
index 60f66e3..1a48998 100644
--- a/style/src/render-helper.cpp
+++ b/style/src/render-helper.cpp
@@ -313,6 +313,7 @@ QPixmap RenderHelper::changeSVGFillColor(const QString &svgFile, const QColor &f
tinyDoc->draw(&tempPainter);
tempPainter.end();
+ delete tinyDoc;
return tempPixmap;
}
@@ -381,4 +382,4 @@ void RenderHelper::renderTabBarTab(QPainter *painter,
painter->drawPath(painterPath);
}
-} // namespace Kiran
\ No newline at end of file
+} // namespace Kiran
--
2.33.0

View File

@ -1,10 +1,11 @@
Name: kiran-qt5-integration
Version: 2.4.0
Release: 1
Release: 2
Summary: Kiran desktop platform integration plugin.
License: MulanPSL-2.0
Source0: %{name}-%{version}.tar.gz
Patch0001: 0001-fix-Memory-leak-Fix-the-memory-leak.patch
BuildRequires: cmake >= 3.2
BuildRequires: gcc-c++
@ -60,6 +61,9 @@ make %{?_smp_mflags}
%{_libdir}/pkgconfig/kiran-style-helper.pc
%changelog
* Fri Nov 25 2022 liuxinhao <liuxinhao@kylinsec.com.cn> - 2.4.0-2
- KYOS-F:Fix the memory leak of change theme
* Mon Oct 31 2022 liuxinhao <liuxinhao@kylinsec.com.cn> - 2.4.0-1
- KYOS-F: Modify the color table and add new color types, and support the 2.4 color block design of the control center