Commit f5e5487b authored by keishi@webkit.org's avatar keishi@webkit.org

NSLocale leaks in LocaleMac

https://bugs.webkit.org/show_bug.cgi?id=97628

Reviewed by Kent Tamura.

We need to adopt the NSLocale object so it doesn't leak and
determineLocale() should return a NSLocale without additional retain.

No new tests.

* platform/text/mac/LocaleMac.mm:
(WebCore::determineLocale): Returns a RetainPtr<NSLocale>.
(WebCore::Locale::create):
(WebCore::LocaleMac::LocaleMac): m_locale should adopt the NSLocale object.
(WebCore::LocaleMac::create): LocaleMac constructor takes NSLocale without additional retain.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@132868 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 70154739
2012-10-29 Keishi Hattori <keishi@webkit.org>
NSLocale leaks in LocaleMac
https://bugs.webkit.org/show_bug.cgi?id=97628
Reviewed by Kent Tamura.
We need to adopt the NSLocale object so it doesn't leak and
determineLocale() should return a NSLocale without additional retain.
No new tests.
* platform/text/mac/LocaleMac.mm:
(WebCore::determineLocale): Returns a RetainPtr<NSLocale>.
(WebCore::Locale::create):
(WebCore::LocaleMac::LocaleMac): m_locale should adopt the NSLocale object.
(WebCore::LocaleMac::create): LocaleMac constructor takes NSLocale without additional retain.
2012-10-29 Charles Wei <charles.wei@torchmobile.com.cn>
[BlackBerry] Disable redirect to data scheme for potential fishing.
......@@ -54,20 +54,20 @@ static inline String languageFromLocale(const String& locale)
return normalizedLocale.left(separatorPosition);
}
static NSLocale* determineLocale(const String& locale)
static RetainPtr<NSLocale> determineLocale(const String& locale)
{
NSLocale* currentLocale = [NSLocale currentLocale];
String currentLocaleLanguage = languageFromLocale(String([currentLocale localeIdentifier]));
RetainPtr<NSLocale> currentLocale = [NSLocale currentLocale];
String currentLocaleLanguage = languageFromLocale(String([currentLocale.get() localeIdentifier]));
String localeLanguage = languageFromLocale(locale);
if (equalIgnoringCase(currentLocaleLanguage, localeLanguage))
return currentLocale;
// It seems initWithLocaleIdentifier accepts dash-separated locale identifier.
return [[NSLocale alloc] initWithLocaleIdentifier:locale];
return RetainPtr<NSLocale>(AdoptNS, [[NSLocale alloc] initWithLocaleIdentifier:locale]);
}
PassOwnPtr<Locale> Locale::create(const AtomicString& locale)
{
return LocaleMac::create(determineLocale(locale.string()));
return LocaleMac::create(determineLocale(locale.string()).get());
}
static RetainPtr<NSDateFormatter> createDateTimeFormatter(NSLocale* locale, NSCalendar* calendar, NSDateFormatterStyle dateStyle, NSDateFormatterStyle timeStyle)
......@@ -90,7 +90,7 @@ LocaleMac::LocaleMac(NSLocale* locale)
// NSLocale returns a lower case NSLocaleLanguageCode so we don't have care about case.
NSString* language = [m_locale.get() objectForKey:NSLocaleLanguageCode];
if ([availableLanguages indexOfObject:language] == NSNotFound)
m_locale = [[NSLocale alloc] initWithLocaleIdentifier:defaultLanguage()];
m_locale.adoptNS([[NSLocale alloc] initWithLocaleIdentifier:defaultLanguage()]);
[m_gregorianCalendar.get() setLocale:m_locale.get()];
}
......@@ -100,7 +100,8 @@ LocaleMac::~LocaleMac()
PassOwnPtr<LocaleMac> LocaleMac::create(const String& localeIdentifier)
{
return adoptPtr(new LocaleMac([[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier]));
RetainPtr<NSLocale> locale = [[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier];
return adoptPtr(new LocaleMac(locale.get()));
}
PassOwnPtr<LocaleMac> LocaleMac::create(NSLocale* locale)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment