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
This commit is contained in:
zty199 2024-06-17 20:57:31 +08:00 committed by deepin-bot[bot]
parent c22fc13355
commit 5b0af3856b

View File

@ -205,9 +205,12 @@ public:
bool trySet(const QString& key, const QVariant& value) 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; bool success = false;
@ -221,6 +224,7 @@ public:
} }
g_variant_unref(cur); g_variant_unref(cur);
g_free(gkey);
return success; return success;
} }