adium-1.4 3648:3d0680a6d02c: XtrasInstaller seems to have some m...

commits at adium.im commits at adium.im
Sat Nov 5 19:17:39 UTC 2011


details:	http://hg.adium.im/adium-1.4/rev/3d0680a6d02c
revision:	3648:3d0680a6d02c
branch:		(none)
author:		Thijs Alkemade <thijsalkemade at gmail.com>
date:		Tue Nov 01 23:49:54 2011 +0100

XtrasInstaller seems to have some memory management failures. Fix these by using properties.

Fixes #15581
(transplanted from 035bd5aaed2704a65297d04d6e9c838c367e11c3)

diffs (203 lines):

diff -r af8314033d64 -r 3d0680a6d02c Source/XtrasInstaller.h
--- a/Source/XtrasInstaller.h	Sun Oct 30 13:35:26 2011 -0400
+++ b/Source/XtrasInstaller.h	Tue Nov 01 23:49:54 2011 +0100
@@ -31,4 +31,9 @@
 -(IBAction)cancel:(id)sender;
 -(void)installXtraAtURL:(NSURL *)url;
 +(XtrasInstaller *)installer;
+
+ at property (retain) NSURLDownload *download;
+ at property (retain) NSString *dest;
+ at property (retain) NSString *xtraName;
+
 @end
diff -r af8314033d64 -r 3d0680a6d02c Source/XtrasInstaller.m
--- a/Source/XtrasInstaller.m	Sun Oct 30 13:35:26 2011 -0400
+++ b/Source/XtrasInstaller.m	Tue Nov 01 23:49:54 2011 +0100
@@ -33,6 +33,8 @@
  */
 @implementation XtrasInstaller
 
+ at synthesize dest, download, xtraName;
+
 //XtrasInstaller does not autorelease because it will release itself when closed
 + (XtrasInstaller *)installer
 {
@@ -42,7 +44,7 @@
 - (id)init
 {
 	if ((self = [super init])) {
-		download = nil;
+		self.download = nil;
 		window = nil;
 	}
 
@@ -52,13 +54,15 @@
 - (void)dealloc
 {
 	[download release];
+	[xtraName release];
+	[dest release];
 
 	[super dealloc];
 }
 
 - (IBAction)cancel:(id)sender;
 {
-	if (download) [download cancel];
+	if (self.download) [self.download cancel];
 	[self closeInstaller];
 }
 
@@ -81,7 +85,7 @@
 		[NSBundle loadNibNamed:@"XtraProgressWindow" owner:self];
 		[progressBar setUsesThreadedAnimation:YES];
 		
-		xtraName = nil;
+		self.xtraName = nil;
 		amountDownloaded = 0;
 		downloadSize = 0;
 		
@@ -98,7 +102,7 @@
 													   ([url query] ? [url query] : @"")]];
 //		dest = [NSTemporaryDirectory() stringByAppendingPathComponent:[[urlToDownload path] lastPathComponent]];
 		AILogWithSignature(@"Downloading %@", urlToDownload);
-		download = [[NSURLDownload alloc] initWithRequest:[NSURLRequest requestWithURL:urlToDownload] delegate:self];
+		self.download = [[NSURLDownload alloc] initWithRequest:[NSURLRequest requestWithURL:urlToDownload] delegate:self];
 //		[download setDestination:dest allowOverwrite:YES];
 
 		[urlToDownload release];
@@ -115,14 +119,14 @@
 - (void)updateInfoText
 {
 	NSInteger				percentComplete = (downloadSize > 0 ? (NSUInteger)(((double)amountDownloaded / (double)downloadSize) * 100.0) : 0);
-	NSString		*installText = [NSString stringWithFormat:AILocalizedString(@"Downloading %@", @"Install an Xtra; %@ is the name of the Xtra."), (xtraName ? xtraName : @"")];
+	NSString		*installText = [NSString stringWithFormat:AILocalizedString(@"Downloading %@", @"Install an Xtra; %@ is the name of the Xtra."), (self.xtraName ? self.xtraName : @"")];
 	
 	[infoText setStringValue:[NSString stringWithFormat:@"%@ (%lu%%)", installText, percentComplete]];
 }
 
 - (void)download:(NSURLDownload *)connection didReceiveResponse:(NSHTTPURLResponse *)response
 {	
-	xtraName = [[response allHeaderFields] objectForKey:@"X-Xtraname"];
+	self.xtraName = [[response allHeaderFields] objectForKey:@"X-Xtraname"];
 	amountDownloaded = 0;
 	downloadSize = [response expectedContentLength];
 	[progressBar setMaxValue:(long long)downloadSize];
@@ -135,9 +139,9 @@
 {
 	NSString * downloadDir = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString uuid]];
 	[[NSFileManager defaultManager] createDirectoryAtPath:downloadDir withIntermediateDirectories:YES attributes:nil error:NULL];
-	dest = [downloadDir stringByAppendingPathComponent:filename];
-	AILogWithSignature(@"Downloading to is %@", dest);
-	[download setDestination:dest allowOverwrite:YES];
+	self.dest = [downloadDir stringByAppendingPathComponent:filename];
+	AILogWithSignature(@"Downloading to is %@", self.dest);
+	[self.download setDestination:self.dest allowOverwrite:YES];
 }
 
 - (void)download:(NSURLDownload *)download didReceiveDataOfLength:(NSUInteger)length
@@ -165,7 +169,7 @@
 }
 
 - (void)downloadDidFinish:(NSURLDownload *)download {
-	NSString		*lastPathComponent = [[dest lowercaseString] lastPathComponent];
+	NSString		*lastPathComponent = [[self.dest lowercaseString] lastPathComponent];
 	NSString		*pathExtension = [lastPathComponent pathExtension];
 	BOOL			decompressionSuccess = YES, success = NO;
 	
@@ -174,8 +178,8 @@
 
 		uncompress = [[NSTask alloc] init];
 		[uncompress setLaunchPath:@"/usr/bin/gunzip"];
-		[uncompress setArguments:[NSArray arrayWithObjects:@"-df" , [dest lastPathComponent] ,  nil]];
-		[uncompress setCurrentDirectoryPath:[dest stringByDeletingLastPathComponent]];
+		[uncompress setArguments:[NSArray arrayWithObjects:@"-df" , [self.dest lastPathComponent] ,  nil]];
+		[uncompress setCurrentDirectoryPath:[self.dest stringByDeletingLastPathComponent]];
 		
 		@try
 		{
@@ -191,16 +195,16 @@
 		
 		if (decompressionSuccess) {
 			if ([pathExtension isEqualToString:@"tgz"]) {
-				dest = [[dest stringByDeletingPathExtension] stringByAppendingPathExtension:@"tar"];
+				self.dest = [[self.dest stringByDeletingPathExtension] stringByAppendingPathExtension:@"tar"];
 			} else {
 				//hasSuffix .tar.gz
-				dest = [dest substringToIndex:[dest length] - 3];//remove the .gz, leaving us with .tar
+				self.dest = [self.dest substringToIndex:[self.dest length] - 3];//remove the .gz, leaving us with .tar
 			}
 			
 			untar = [[NSTask alloc] init];
 			[untar setLaunchPath:@"/usr/bin/tar"];
-			[untar setArguments:[NSArray arrayWithObjects:@"-xvf", [dest lastPathComponent], nil]];
-			[untar setCurrentDirectoryPath:[dest stringByDeletingLastPathComponent]];
+			[untar setArguments:[NSArray arrayWithObjects:@"-xvf", [self.dest lastPathComponent], nil]];
+			[untar setCurrentDirectoryPath:[self.dest stringByDeletingLastPathComponent]];
 			
 			@try
 			{
@@ -223,11 +227,11 @@
 		[unzip setArguments:[NSArray arrayWithObjects:
 			@"-o",  /* overwrite */
 			@"-q", /* quiet! */
-			dest, /* source zip file */
-			@"-d", [dest stringByDeletingLastPathComponent], /*destination folder*/
+			self.dest, /* source zip file */
+			@"-d", [self.dest stringByDeletingLastPathComponent], /*destination folder*/
 			nil]];
 
-		[unzip setCurrentDirectoryPath:[dest stringByDeletingLastPathComponent]];
+		[unzip setCurrentDirectoryPath:[self.dest stringByDeletingLastPathComponent]];
 
 		@try
 		{
@@ -250,15 +254,15 @@
 	//Delete the compressed xtra, now that we've decompressed it
 #ifdef DEBUG_BUILD
 	if (decompressionSuccess)
-		[fileManager removeItemAtPath:dest error:NULL];
+		[fileManager removeItemAtPath:self.dest error:NULL];
 #else
-	[fileManager removeItemAtPath:dest error:NULL];
+	[fileManager removeItemAtPath:self.dest error:NULL];
 #endif
 	
-	dest = [dest stringByDeletingLastPathComponent];
+	self.dest = [self.dest stringByDeletingLastPathComponent];
 	
 	//the remaining files in the directory should be the contents of the xtra
-	fileEnumerator = [fileManager enumeratorAtPath:dest];
+	fileEnumerator = [fileManager enumeratorAtPath:self.dest];
 
 	if (decompressionSuccess && fileEnumerator) {
 		NSSet			*supportedDocumentExtensions = [[NSBundle mainBundle] supportedDocumentExtensions];
@@ -282,7 +286,7 @@
 				}
 
 				if (isSupported) {
-					NSString *xtraPath = [dest stringByAppendingPathComponent:nextFile];
+					NSString *xtraPath = [self.dest stringByAppendingPathComponent:nextFile];
 
 					//Open the file directly
 					AILogWithSignature(@"Installing %@",xtraPath);
@@ -297,15 +301,15 @@
 		}
 		
 	} else {
-		NSLog(@"Installation Error: %@ (%@)",dest, (decompressionSuccess ? @"Decompressed succesfully" : @"Failed to decompress"));
+		NSLog(@"Installation Error: %@ (%@)",self.dest, (decompressionSuccess ? @"Decompressed succesfully" : @"Failed to decompress"));
 	}
 	
 	//delete our temporary directory, and any files remaining in it
 #ifdef DEBUG_BUILD
 	if (success)
-		[fileManager removeItemAtPath:dest error:NULL];
+		[fileManager removeItemAtPath:self.dest error:NULL];
 #else
-	[fileManager removeItemAtPath:dest error:NULL];
+	[fileManager removeItemAtPath:self.dest error:NULL];
 #endif
 
 	[self closeInstaller];




More information about the commits mailing list