Fix #35890: memory leak in OS X ghost locale detection.

This commit is contained in:
Brecht Van Lommel
2013-06-27 13:24:55 +00:00
parent ee85587a43
commit b466a5c9a9
2 changed files with 6 additions and 4 deletions

View File

@@ -549,7 +549,7 @@ int cocoa_request_qtcodec_settings(bContext *C, wmOperator *op)
#pragma mark initialization/finalization #pragma mark initialization/finalization
const char *user_locale; // Global current user locale char GHOST_user_locale[128]; // Global current user locale
GHOST_SystemCocoa::GHOST_SystemCocoa() GHOST_SystemCocoa::GHOST_SystemCocoa()
{ {
@@ -590,11 +590,13 @@ GHOST_SystemCocoa::GHOST_SystemCocoa()
m_ignoreWindowSizedMessages = false; m_ignoreWindowSizedMessages = false;
//Get current locale //Get current locale
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CFLocaleRef myCFLocale = CFLocaleCopyCurrent(); CFLocaleRef myCFLocale = CFLocaleCopyCurrent();
NSLocale * myNSLocale = (NSLocale *) myCFLocale; NSLocale * myNSLocale = (NSLocale *) myCFLocale;
[myNSLocale autorelease]; [myNSLocale autorelease];
NSString *nsIdentifier = [myNSLocale localeIdentifier]; NSString *nsIdentifier = [myNSLocale localeIdentifier];
user_locale = [nsIdentifier UTF8String]; strncpy(GHOST_user_locale, [nsIdentifier UTF8String], sizeof(GHOST_user_locale) - 1);
[pool drain];
} }
GHOST_SystemCocoa::~GHOST_SystemCocoa() GHOST_SystemCocoa::~GHOST_SystemCocoa()

View File

@@ -65,8 +65,8 @@ void bl_locale_set(const char *locale)
} }
else { else {
#ifdef __APPLE__ #ifdef __APPLE__
extern const char *user_locale; // pulled from Ghost_SystemCocoa extern char GHOST_user_locale[128]; // pulled from Ghost_SystemCocoa
std::string locale_osx = user_locale + std::string(".UTF-8"); std::string locale_osx = GHOST_user_locale + std::string(".UTF-8");
_locale = gen(locale_osx.c_str()); _locale = gen(locale_osx.c_str());
#else #else
_locale = gen(""); _locale = gen("");