diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2017-11-16 22:40:50 +0100 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-11-17 15:32:38 +0100 |
commit | 5ad6e168c60c0ae184f73c0f7a4c8a3ebd66315d (patch) | |
tree | 12a9416048ebaefa7d84878996ec25a3c1bb1316 | |
parent | 9ec7aa7fd730da140639052e8831ff5c910fc6cb (diff) | |
download | subsurface-5ad6e168c60c0ae184f73c0f7a4c8a3ebd66315d.tar.gz |
Fix memory leaks in SettingsObjectWrapper.cpp
Free a bunch of C-style strings before assigning newly copied strings.
One case was particularly buggy:
prefs.locale.use_system_language = copy_string(qPrintable(value));
Note that prefs.locale.use_system_language is a bool, which of course
always evaluates to true! Probably nobody noticed because a restart
is required when changing locale.
Moreover remove a few double-semicolons.
-rw-r--r-- | core/subsurface-qt/SettingsObjectWrapper.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index 16987d6ae..efd1cda6c 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -748,6 +748,7 @@ void FacebookSettings::setAccessToken (const QString& value) s.beginGroup(subgroup); s.setValue("ConnectToken", value); #endif + free(prefs.facebook.access_token); prefs.facebook.access_token = copy_string(qPrintable(value)); emit accessTokenChanged(value); } @@ -762,6 +763,7 @@ void FacebookSettings::setUserId(const QString& value) s.beginGroup(subgroup); s.setValue("UserId", value); #endif + free(prefs.facebook.user_id); prefs.facebook.user_id = copy_string(qPrintable(value)); emit userIdChanged(value); } @@ -776,6 +778,7 @@ void FacebookSettings::setAlbumId(const QString& value) s.beginGroup(subgroup); s.setValue("AlbumId", value); #endif + free(prefs.facebook.album_id); prefs.facebook.album_id = copy_string(qPrintable(value)); emit albumIdChanged(value); } @@ -889,7 +892,7 @@ void ProxySettings::setHost(const QString& value) s.beginGroup(group); s.setValue("proxy_host", value); free(prefs.proxy_host); - prefs.proxy_host = copy_string(qPrintable(value));; + prefs.proxy_host = copy_string(qPrintable(value)); emit hostChanged(value); } @@ -1792,6 +1795,7 @@ void GeneralSettingsObjectWrapper::setDefaultFilename(const QString& value) QSettings s; s.beginGroup(group); s.setValue("default_filename", value); + free((void*)prefs.default_filename); prefs.default_filename = copy_string(qPrintable(value)); emit defaultFilenameChanged(value); } @@ -1804,6 +1808,7 @@ void GeneralSettingsObjectWrapper::setDefaultCylinder(const QString& value) QSettings s; s.beginGroup(group); s.setValue("default_cylinder", value); + free((void*)prefs.default_cylinder); prefs.default_cylinder = copy_string(qPrintable(value)); emit defaultCylinderChanged(value); } @@ -1996,7 +2001,7 @@ void LanguageSettingsObjectWrapper::setUseSystemLanguage(bool value) QSettings s; s.beginGroup(group); s.setValue("UseSystemLanguage", value); - prefs.locale.use_system_language = copy_string(qPrintable(value)); + prefs.locale.use_system_language = value; emit useSystemLanguageChanged(value); } @@ -2007,6 +2012,7 @@ void LanguageSettingsObjectWrapper::setLangLocale(const QString &value) QSettings s; s.beginGroup(group); s.setValue("UiLangLocale", value); + free((void*)prefs.locale.lang_locale); prefs.locale.lang_locale = copy_string(qPrintable(value)); emit langLocaleChanged(value); } @@ -2018,6 +2024,7 @@ void LanguageSettingsObjectWrapper::setLanguage(const QString& value) QSettings s; s.beginGroup(group); s.setValue("UiLanguage", value); + free((void*)prefs.locale.language); prefs.locale.language = copy_string(qPrintable(value)); emit languageChanged(value); } @@ -2029,7 +2036,8 @@ void LanguageSettingsObjectWrapper::setTimeFormat(const QString& value) QSettings s; s.beginGroup(group); s.setValue("time_format", value); - prefs.time_format = copy_string(qPrintable(value));; + free((void*)prefs.time_format); + prefs.time_format = copy_string(qPrintable(value)); emit timeFormatChanged(value); } @@ -2041,7 +2049,8 @@ void LanguageSettingsObjectWrapper::setDateFormat(const QString& value) QSettings s; s.beginGroup(group); s.setValue("date_format", value); - prefs.date_format = copy_string(qPrintable(value));; + free((void*)prefs.date_format); + prefs.date_format = copy_string(qPrintable(value)); emit dateFormatChanged(value); } @@ -2053,7 +2062,8 @@ void LanguageSettingsObjectWrapper::setDateFormatShort(const QString& value) QSettings s; s.beginGroup(group); s.setValue("date_format_short", value); - prefs.date_format_short = copy_string(qPrintable(value));; + free((void*)prefs.date_format_short); + prefs.date_format_short = copy_string(qPrintable(value)); emit dateFormatShortChanged(value); } |