From 1bbc2994dd68788bf58545d2dca309745567fa39 Mon Sep 17 00:00:00 2001 From: "stuart.morgan%alumni.case.edu" Date: Mon, 24 Nov 2008 20:05:02 +0000 Subject: [PATCH] Camino only - Bug 465493: Don't leak when doing localized string lookup on a background thread. sr=pink git-svn-id: svn://10.0.0.236/trunk@255190 18797224-902f-48f8-a5cc-f745e15eee43 --- .../src/embedding/CHStringBundleOverride.mm | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/mozilla/camino/src/embedding/CHStringBundleOverride.mm b/mozilla/camino/src/embedding/CHStringBundleOverride.mm index f4387136aa6..6418bccc76e 100644 --- a/mozilla/camino/src/embedding/CHStringBundleOverride.mm +++ b/mozilla/camino/src/embedding/CHStringBundleOverride.mm @@ -61,19 +61,36 @@ NS_IMETHODIMP CHStringBundleOverride::GetStringFromName(const nsACString& url, c * service to replace the string. If not, then the |nsIStringBundle| will use the string * defined in the bundled chrome resource. */ - NSString* keyStr = [NSString stringWith_nsACString:key]; - NSString* tableName = [NSString stringWith_nsACString:url]; - // Stip off the chrome:// prefix (9 characters) if it's there - if ([tableName hasPrefix:@"chrome://"]) - tableName = [tableName substringFromIndex:9]; - NSCharacterSet* replacementSet = [NSCharacterSet characterSetWithCharactersInString:@"/."]; - tableName = [tableName stringByReplacingCharactersInSet:replacementSet - withString:@"_"]; - NSString* overrideStr = NSLocalizedStringFromTable(keyStr, tableName, nil); - if (!overrideStr || [overrideStr isEqualToString:keyStr]) + @try { + // Create an autorelease pool, since this may be called on a background thread. + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + NSString* keyStr = [NSString stringWith_nsACString:key]; + NSString* tableName = [NSString stringWith_nsACString:url]; + // Stip off the chrome:// prefix (9 characters) if it's there + if ([tableName hasPrefix:@"chrome://"]) + tableName = [tableName substringFromIndex:9]; + NSCharacterSet* replacementSet = [NSCharacterSet characterSetWithCharactersInString:@"/."]; + tableName = [tableName stringByReplacingCharactersInSet:replacementSet + withString:@"_"]; + NSString* overrideStr = NSLocalizedStringFromTable(keyStr, tableName, nil); + if (!overrideStr || [overrideStr isEqualToString:keyStr]) { + [pool release]; + return NS_ERROR_FAILURE; + } + + [overrideStr assignTo_nsAString:aRetVal]; + + [pool release]; + } + @catch (id exception) { + // Note that we may leak the autorelease pool if this happens on a + // background thread, but there's not really a safe way to handle that + // case; see the discussion at: + // http://lists.apple.com/archives/objc-language//2007/Aug/msg00023.html + NSLog(@"Exception caught in CHStringBundleOverride::GetStringFromName %@", exception); return NS_ERROR_FAILURE; - - [overrideStr assignTo_nsAString:aRetVal]; + } return NS_OK; }