summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <[email protected]>2023-08-03 16:09:49 +0200
committerThorbjørn Lindeijer <[email protected]>2023-08-03 21:15:55 +0200
commit233e7e6be35a5a455b6ecd7c15de8c9cfc70ca10 (patch)
tree45172faa8d5a21f7ce3dc96903672473560511f4
parent40b063cd745136c1c0be4c9903955218ef647a02 (diff)
Fix memory leak in QGtk3Interface::themeName
Pick-to: 6.6 6.5 Change-Id: Ib8c90f7ef66c095f0c1fc04f4cc72bf5eea72ddb Reviewed-by: Axel Spoerl <[email protected]>
-rw-r--r--src/plugins/platformthemes/gtk3/qgtk3interface.cpp17
-rw-r--r--src/plugins/platformthemes/gtk3/qgtk3interface_p.h2
2 files changed, 11 insertions, 8 deletions
diff --git a/src/plugins/platformthemes/gtk3/qgtk3interface.cpp b/src/plugins/platformthemes/gtk3/qgtk3interface.cpp
index 758a5095af9..5229cb73460 100644
--- a/src/plugins/platformthemes/gtk3/qgtk3interface.cpp
+++ b/src/plugins/platformthemes/gtk3/qgtk3interface.cpp
@@ -475,15 +475,18 @@ QBrush QGtk3Interface::brush(QGtkWidget wtype, QGtkColorSource source, GtkStateF
\internal
\brief Returns the name of the current GTK theme.
*/
-const QString QGtk3Interface::themeName() const
+QString QGtk3Interface::themeName() const
{
- gchar *theme_name;
- GtkSettings *settings = gtk_settings_get_default();
- if (!settings)
- return QString();
+ QString name;
+
+ if (GtkSettings *settings = gtk_settings_get_default()) {
+ gchar *theme_name;
+ g_object_get(settings, "gtk-theme-name", &theme_name, nullptr);
+ name = QLatin1StringView(theme_name);
+ g_free(theme_name);
+ }
- g_object_get(settings, "gtk-theme-name", &theme_name, nullptr);
- return QLatin1StringView(theme_name);
+ return name;
}
/*!
diff --git a/src/plugins/platformthemes/gtk3/qgtk3interface_p.h b/src/plugins/platformthemes/gtk3/qgtk3interface_p.h
index b92adcd7203..c43932a4fa3 100644
--- a/src/plugins/platformthemes/gtk3/qgtk3interface_p.h
+++ b/src/plugins/platformthemes/gtk3/qgtk3interface_p.h
@@ -134,7 +134,7 @@ public:
QIcon fileIcon(const QFileInfo &fileInfo) const;
// Return current GTK theme name
- const QString themeName() const;
+ QString themeName() const;
// Derive color scheme from default colors
Qt::ColorScheme colorSchemeByColors() const;