adium 4276:035bd5aaed27: XtrasInstaller seems to have some memor...
commits at adium.im
commits at adium.im
Tue Nov 1 22:50:16 UTC 2011
details: http://hg.adium.im/adium/rev/035bd5aaed27
revision: 4276:035bd5aaed27
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
diffs (229 lines):
diff -r 2d15405b6d71 -r 035bd5aaed27 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 2d15405b6d71 -r 035bd5aaed27 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];
}
@@ -100,7 +104,7 @@
AILogWithSignature(@"Downloading %@", urlToDownload);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlToDownload];
[request setHTTPShouldHandleCookies:NO];
- download = [[NSURLDownload alloc] initWithRequest:request delegate:self];
+ self.download = [[NSURLDownload alloc] initWithRequest:request delegate:self];
// [download setDestination:dest allowOverwrite:YES];
[urlToDownload release];
@@ -117,14 +121,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];
@@ -137,9 +141,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
@@ -193,7 +197,7 @@
}
- (void)downloadDidFinish:(NSURLDownload *)inDownload {
- NSString *lastPathComponent = [dest lastPathComponent];
+ NSString *lastPathComponent = [self.dest lastPathComponent];
NSString *pathExtension = [[lastPathComponent pathExtension] lowercaseString];
BOOL decompressionSuccess = YES, success = NO;
@@ -202,8 +206,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
{
@@ -219,16 +223,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
{
@@ -251,11 +255,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
{
@@ -278,17 +282,17 @@
//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];
FSRef fsRef;
OSStatus err;
- if (FSPathMakeRef((const UInt8 *)[dest fileSystemRepresentation], &fsRef, NULL) == noErr) {
+ if (FSPathMakeRef((const UInt8 *)[self.dest fileSystemRepresentation], &fsRef, NULL) == noErr) {
NSMutableDictionary *quarantineProperties = nil;
CFTypeRef cfOldQuarantineProperties = NULL;
@@ -300,7 +304,7 @@
if (CFGetTypeID(cfOldQuarantineProperties) == CFDictionaryGetTypeID()) {
quarantineProperties = [[(NSDictionary *)cfOldQuarantineProperties mutableCopy] autorelease];
} else {
- AILogWithSignature(@"Getting quarantine data failed for %@ (%@)", self, dest);
+ AILogWithSignature(@"Getting quarantine data failed for %@ (%@)", self, self.dest);
return;
}
@@ -319,19 +323,19 @@
[quarantineProperties setObject:(NSString *)kLSQuarantineTypeWebDownload
forKey:(NSString *)kLSQuarantineTypeKey];
- [quarantineProperties setObject:[[download request] URL]
+ [quarantineProperties setObject:[[self.download request] URL]
forKey:(NSString *)kLSQuarantineDataURLKey];
[self setQuarantineProperties:quarantineProperties forDirectory:&fsRef];
- AILogWithSignature(@"Quarantined %@ with %@", dest, quarantineProperties);
+ AILogWithSignature(@"Quarantined %@ with %@", self.dest, quarantineProperties);
} else {
- AILogWithSignature(@"Danger! Could not find file to quarantine: %@!", dest);
+ AILogWithSignature(@"Danger! Could not find file to quarantine: %@!", self.dest);
}
//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];
@@ -356,7 +360,7 @@
}
if (isSupported) {
- NSString *xtraPath = [dest stringByAppendingPathComponent:nextFile];
+ NSString *xtraPath = [self.dest stringByAppendingPathComponent:nextFile];
//Open the file directly
AILogWithSignature(@"Installing %@",xtraPath);
@@ -371,15 +375,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