diff --git a/ChangeLog b/ChangeLog index 92849f62f..21fef9fe6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-12-21 Richard Frith-Macdonald + + * Source/GSLocale.m: protect locale access with locks. + 2007-12-21 David Ayers * Source/NSPathUtilities.m (_POSIX_PTHREAD_SEMANTICS): Define to expose diff --git a/Source/GSLocale.m b/Source/GSLocale.m index 6d0e1b3b6..88addf522 100644 --- a/Source/GSLocale.m +++ b/Source/GSLocale.m @@ -108,6 +108,11 @@ GSDomainFromDefaultLocale(void) dict = [NSMutableDictionary dictionary]; + /* Protect locale access with locks to prevent multiple threads using + * it and interfering with the buffer. + */ + [gnustep_global_lock lock]; + #ifdef HAVE_LANGINFO_H /* Time/Date Information */ arr = [NSMutableArray arrayWithCapacity: 7]; @@ -189,7 +194,6 @@ GSDomainFromDefaultLocale(void) forKey: NSThousandsSeparator]; } - /* FIXME: Get currency format from localeconv */ #ifdef LC_MESSAGES @@ -207,7 +211,6 @@ GSDomainFromDefaultLocale(void) [dict setObject: str2 forKey: NSLanguageName]; } - [gnustep_global_lock lock]; /* * Another thread might have been faster in setting the static variable. * If so, we just drop our dict. diff --git a/Source/NSUserDefaults.m b/Source/NSUserDefaults.m index 470df9daf..bbf43dda2 100644 --- a/Source/NSUserDefaults.m +++ b/Source/NSUserDefaults.m @@ -266,14 +266,20 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */ { NSDictionary *regDefs; - [sharedDefaults synchronize]; // Ensure changes are written. - regDefs = RETAIN([sharedDefaults->_tempDomains - objectForKey: NSRegistrationDomain]); /* To ensure that we don't try to synchronise the old defaults to disk * after creating the new ones, remove as housekeeping notification * observer. */ [[NSNotificationCenter defaultCenter] removeObserver: sharedDefaults]; + + /* Ensure changes are written, and no changes left so we can't end up + * writing old changes to the new defaults. + */ + [sharedDefaults synchronize]; + DESTROY(sharedDefaults->_changedDomains); + + regDefs = RETAIN([sharedDefaults->_tempDomains + objectForKey: NSRegistrationDomain]); setSharedDefaults = NO; DESTROY(sharedDefaults); if (regDefs != nil)