From 5b0af3856b4978965fe6cd1eec8343d4e7e4d300 Mon Sep 17 00:00:00 2001 From: zty199 <46324746+zty199@users.noreply.github.com> Date: Mon, 17 Jun 2024 20:57:31 +0800 Subject: [PATCH] fix: crash when calling DGioSettings::setValue Though whether key is actually existed has been judged in DGioSettingsPrivate::trySet, when calling g_settings_get_value, 'gkey' still seems to be empty or NULL. Not sure what happened when converted from QString to gchar* Log: Use DGioPrivate::convertToGChar to replace QString::toUtf8().constData() in DGioSettingsPrivate::trySet, just like DGioSettingsPrivate::value --- gio-qt/source/dgiosettings.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gio-qt/source/dgiosettings.cpp b/gio-qt/source/dgiosettings.cpp index c7c7c58..ea241ab 100644 --- a/gio-qt/source/dgiosettings.cpp +++ b/gio-qt/source/dgiosettings.cpp @@ -205,9 +205,12 @@ public: bool trySet(const QString& key, const QVariant& value) { - const gchar* gkey = key.toUtf8().constData(); + gchar* gkey = DGioPrivate::converToGChar(key.toUtf8()); - if(!inlcudeKey(gkey)) return false; + if(!inlcudeKey(gkey)) { + g_free(gkey); + return false; + } bool success = false; @@ -221,6 +224,7 @@ public: } g_variant_unref(cur); + g_free(gkey); return success; }