From c89cc865caa7671f968f36b3e61c6dc435f724db Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 18 Oct 2015 22:04:58 +0200 Subject: [PATCH] Fix wxLocale::IsOk() in case of initialization failure Ever since 700256bbdbf40042ecadad340f7909589a8f7ecc IsOk() returned true even if setting the locale actually failed because the old locale was still set to the null value. Apply the minimal possible fix for this and just reset the old locale pointer to null if initializing the locale fails to make sure IsOk() doesn't return true in this case. --- docs/changes.txt | 1 + src/common/intl.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index aadd29d3a4..0efb5c6028 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -580,6 +580,7 @@ Major new features in this release All: - Fix wxFileName::MakeRelativeTo() for directory relatively to itself. +- Fix wxLocale::IsOk() return true even if setting the locale failed. Unix: diff --git a/src/common/intl.cpp b/src/common/intl.cpp index e7849ea58c..745cff6944 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -554,6 +554,11 @@ bool wxLocale::Init(int language, int flags) { wxLogWarning(_("Cannot set locale to language \"%s\"."), name.c_str()); + // As we failed to change locale, there is no need to restore the + // previous one: it's still valid. + free(const_cast(m_pszOldLocale)); + m_pszOldLocale = NULL; + // continue nevertheless and try to load at least the translations for // this language } @@ -1048,8 +1053,11 @@ wxLocale::~wxLocale() // restore old locale pointer wxSetLocale(m_pOldLocale); - wxSetlocale(LC_ALL, m_pszOldLocale); - free(const_cast(m_pszOldLocale)); + if ( m_pszOldLocale ) + { + wxSetlocale(LC_ALL, m_pszOldLocale); + free(const_cast(m_pszOldLocale)); + } }