From 525371f50b6edda310f10fb468d790abb62539bb Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Mon, 7 Feb 2011 17:21:00 +0000 Subject: [PATCH] locale tweaks git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32006 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ Source/NSLocale.m | 20 +++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8553dc4e0..32e3c6e7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-02-07 Richard Frith-Macdonald + + * Source/NSLocale.m: Fix canonical identifiers to return the input + string if no other value is found. Refrain from putting nil locale + identifier in dictionary. Fix leak of components dictionary when + returning an existing locale by id. + 2011-02-04 Richard Frith-Macdonald * Source/NSConcretePointerFunctions.m: objects with weak memory should diff --git a/Source/NSLocale.m b/Source/NSLocale.m index ea3282c4b..237c2b254 100644 --- a/Source/NSLocale.m +++ b/Source/NSLocale.m @@ -273,9 +273,15 @@ static NSRecursiveLock *classLock = nil; [self _updateCanonicalLocales]; localeId = [canonicalLocales objectForKey: string]; - localeComps = [localeId componentsSeparatedByString: @"_"]; - result = [localeComps objectAtIndex: 0]; - + if (nil == localeId) + { + result = string; + } + else + { + localeComps = [localeId componentsSeparatedByString: @"_"]; + result = [localeComps objectAtIndex: 0]; + } return result; } @@ -736,12 +742,18 @@ static NSRecursiveLock *classLock = nil; #else localeId = [NSLocale canonicalLocaleIdentifierFromString: string]; #endif + if (nil == localeId) + { + [self release]; + return nil; + } [classLock lock]; newLocale = [allLocales objectForKey: localeId]; if (nil == newLocale) { _localeId = [localeId copy]; + _components = [[NSMutableDictionary alloc] initWithCapacity: 0]; [allLocales setObject: self forKey: localeId]; } else @@ -750,8 +762,6 @@ static NSRecursiveLock *classLock = nil; self = [newLocale retain]; } [classLock unlock]; - - _components = [[NSMutableDictionary alloc] initWithCapacity: 0]; return self; }