kiran-qt5-integration/0001-fix-Memory-leak-Fix-the-memory-leak.patch

65 lines
2.4 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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