From c1db961ab9b7aa9c0dd43cadf850b7527b77e95b Mon Sep 17 00:00:00 2001
From: Aura Linden <aura@lindenlab.com>
Date: Sun, 16 Dec 2012 17:45:55 -0800
Subject: [PATCH] Fixed small one-time memory leaks.

---
 indra/llvfs/llvfs_objc.mm                  | 23 +++++++++++++++++++---
 indra/mac_updater/MacUpdaterAppDelegate.mm | 22 +++++++++++++++++++--
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/indra/llvfs/llvfs_objc.mm b/indra/llvfs/llvfs_objc.mm
index 16cfefda26f..4f9e2f81e93 100644
--- a/indra/llvfs/llvfs_objc.mm
+++ b/indra/llvfs/llvfs_objc.mm
@@ -32,16 +32,22 @@
 
 std::string* getSystemTempFolder()
 {
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     NSString * tempDir = NSTemporaryDirectory();
     if (tempDir == nil)
         tempDir = @"/tmp";
-    return ( new std::string([tempDir UTF8String]) );
+    std::string *result = ( new std::string([tempDir UTF8String]) );
+    [pool release];
+    
+    return result;
 }
 
 //findSystemDirectory scoped exclusively to this file. 
 std::string* findSystemDirectory(NSSearchPathDirectory searchPathDirectory,
                                    NSSearchPathDomainMask domainMask)
 {
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    
     std::string *result;
     NSString *path = nil;
     
@@ -60,19 +66,30 @@ std::string* findSystemDirectory(NSSearchPathDirectory searchPathDirectory,
         
         result = new std::string([path UTF8String]);        
     }
+    [pool release];
     return result;
 }
 
 std::string* getSystemExecutableFolder()
 {
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
     NSString *bundlePath = [[NSBundle mainBundle] executablePath];
-    return (new std::string([bundlePath UTF8String]));  
+    std::string *result = (new std::string([bundlePath UTF8String]));  
+    [pool release];
+
+    return result;
 }
 
 std::string* getSystemResourceFolder()
 {
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
     NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
-    return (new std::string([bundlePath UTF8String]));
+    std::string *result = (new std::string([bundlePath UTF8String]));
+    [pool release];
+    
+    return result;
 }
 
 std::string* getSystemCacheFolder()
diff --git a/indra/mac_updater/MacUpdaterAppDelegate.mm b/indra/mac_updater/MacUpdaterAppDelegate.mm
index 3ddf8f92744..b6f95eef7e1 100644
--- a/indra/mac_updater/MacUpdaterAppDelegate.mm
+++ b/indra/mac_updater/MacUpdaterAppDelegate.mm
@@ -126,6 +126,8 @@ void sendProgress(int cur, int max, const std::string str)
 
 bool copyDir(const std::string& src_dir, const std::string& dest_dir)
 {
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
     NSString* file = [NSString stringWithCString:src_dir.c_str() 
                                          encoding:[NSString defaultCStringEncoding]];
     NSString* toParent = [NSString stringWithCString:dest_dir.c_str() 
@@ -137,6 +139,8 @@ bool copyDir(const std::string& src_dir, const std::string& dest_dir)
     if (!result) {
         NSLog(@"Error during copy: %@", [error localizedDescription]);
     }
+    [pool release];
+    
     return result;
 }
 
@@ -178,26 +182,38 @@ bool copyDir(const std::string& src_dir, const std::string& dest_dir)
 
 bool isDirWritable(const std::string& dir_name)
 {
-    
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
     NSString *fullPath = [NSString stringWithCString:dir_name.c_str() 
                                             encoding:[NSString defaultCStringEncoding]];
 
     NSFileManager *fm = [NSFileManager defaultManager];
     bool result = [fm isWritableFileAtPath:fullPath];
+    [pool release];
     
 	return result;
 }
 
 std::string* getUserTrashFolder()
 {
+    std::string *result;
+    
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
     NSString *trash_str=[NSHomeDirectory() stringByAppendingPathComponent:@".Trash"];
-    return NSToString( trash_str );
+    
+    result = NSToString( trash_str );
+    
+    [pool release];
+    return result;
 
 }
 
 bool isFSRefViewerBundle(const std::string& targetURL)
 {
 	bool result = false;
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
     NSString *fullPath = [NSString stringWithCString:targetURL.c_str() 
                                             encoding:[NSString defaultCStringEncoding]];
     NSBundle *targetBundle = [NSBundle bundleWithPath:fullPath];
@@ -212,6 +228,8 @@ bool isFSRefViewerBundle(const std::string& targetURL)
         std::cout << "Target bundle ID mismatch." << std::endl;
     }
     
+    [pool release];
+    
 	return result;
 }
 
-- 
GitLab