Ben Copsey

Fix leaking CoreFoundation stuff when running with GC

@@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
30 #pragma mark utilities 30 #pragma mark utilities
31 - (NSString*)encodeURL:(NSString *)string 31 - (NSString*)encodeURL:(NSString *)string
32 { 32 {
33 - NSString *newString = [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"), CFStringConvertNSStringEncodingToEncoding([self stringEncoding])) autorelease]; 33 + NSString *newString = NSMakeCollectable([(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"), CFStringConvertNSStringEncodingToEncoding([self stringEncoding])) autorelease]);
34 if (newString) { 34 if (newString) {
35 return newString; 35 return newString;
36 } 36 }
@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 23
24 24
25 // Automatically set on build 25 // Automatically set on build
26 -NSString *ASIHTTPRequestVersion = @"v1.6.2-22 2010-06-19"; 26 +NSString *ASIHTTPRequestVersion = @"v1.6.2-23 2010-06-20";
27 27
28 NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; 28 NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";
29 29
@@ -871,13 +871,13 @@ static BOOL isiPhoneOS2; @@ -871,13 +871,13 @@ static BOOL isiPhoneOS2;
871 // Can't detect proxies in 2.2.1 Simulator 871 // Can't detect proxies in 2.2.1 Simulator
872 NSDictionary *proxySettings = [NSMutableDictionary dictionary]; 872 NSDictionary *proxySettings = [NSMutableDictionary dictionary];
873 #else 873 #else
874 - NSDictionary *proxySettings = [(NSDictionary *)CFNetworkCopySystemProxySettings() autorelease]; 874 + NSDictionary *proxySettings = NSMakeCollectable([(NSDictionary *)CFNetworkCopySystemProxySettings() autorelease]);
875 #endif 875 #endif
876 #else 876 #else
877 - NSDictionary *proxySettings = [(NSDictionary *)SCDynamicStoreCopyProxies(NULL) autorelease]; 877 + NSDictionary *proxySettings = NSMakeCollectable([(NSDictionary *)SCDynamicStoreCopyProxies(NULL) autorelease]);
878 #endif 878 #endif
879 879
880 - proxies = [(NSArray *)CFNetworkCopyProxiesForURL((CFURLRef)[self url], (CFDictionaryRef)proxySettings) autorelease]; 880 + proxies = NSMakeCollectable([(NSArray *)CFNetworkCopyProxiesForURL((CFURLRef)[self url], (CFDictionaryRef)proxySettings) autorelease]);
881 881
882 // Now check to see if the proxy settings contained a PAC url, we need to run the script to get the real list of proxies if so 882 // Now check to see if the proxy settings contained a PAC url, we need to run the script to get the real list of proxies if so
883 NSDictionary *settings = [proxies objectAtIndex:0]; 883 NSDictionary *settings = [proxies objectAtIndex:0];
@@ -1169,7 +1169,7 @@ static BOOL isiPhoneOS2; @@ -1169,7 +1169,7 @@ static BOOL isiPhoneOS2;
1169 [self setLastBytesSent:totalBytesSent]; 1169 [self setLastBytesSent:totalBytesSent];
1170 1170
1171 // Find out how much data we've uploaded so far 1171 // Find out how much data we've uploaded so far
1172 - [self setTotalBytesSent:[[(NSNumber *)CFReadStreamCopyProperty((CFReadStreamRef)[self readStream], kCFStreamPropertyHTTPRequestBytesWrittenCount) autorelease] unsignedLongLongValue]]; 1172 + [self setTotalBytesSent:[NSMakeCollectable([(NSNumber *)CFReadStreamCopyProperty((CFReadStreamRef)[self readStream], kCFStreamPropertyHTTPRequestBytesWrittenCount) autorelease]) unsignedLongLongValue]];
1173 if (totalBytesSent > lastBytesSent) { 1173 if (totalBytesSent > lastBytesSent) {
1174 1174
1175 // We've uploaded more data, reset the timeout 1175 // We've uploaded more data, reset the timeout
@@ -1772,7 +1772,7 @@ static BOOL isiPhoneOS2; @@ -1772,7 +1772,7 @@ static BOOL isiPhoneOS2;
1772 if ([self shouldAttemptPersistentConnection]) { 1772 if ([self shouldAttemptPersistentConnection]) {
1773 1773
1774 NSString *connectionHeader = [[[self responseHeaders] objectForKey:@"Connection"] lowercaseString]; 1774 NSString *connectionHeader = [[[self responseHeaders] objectForKey:@"Connection"] lowercaseString];
1775 - NSString *httpVersion = [(NSString *)CFHTTPMessageCopyVersion(message) autorelease]; 1775 + NSString *httpVersion = NSMakeCollectable([(NSString *)CFHTTPMessageCopyVersion(message) autorelease]);
1776 1776
1777 // Don't re-use the connection if the server is HTTP 1.0 and didn't send Connection: Keep-Alive 1777 // Don't re-use the connection if the server is HTTP 1.0 and didn't send Connection: Keep-Alive
1778 if (![httpVersion isEqualToString:(NSString *)kCFHTTPVersion1_0] || [connectionHeader isEqualToString:@"keep-alive"]) { 1778 if (![httpVersion isEqualToString:(NSString *)kCFHTTPVersion1_0] || [connectionHeader isEqualToString:@"keep-alive"]) {
@@ -2551,7 +2551,7 @@ static BOOL isiPhoneOS2; @@ -2551,7 +2551,7 @@ static BOOL isiPhoneOS2;
2551 [progressLock lock]; 2551 [progressLock lock];
2552 // Find out how much data we've uploaded so far 2552 // Find out how much data we've uploaded so far
2553 [self setLastBytesSent:totalBytesSent]; 2553 [self setLastBytesSent:totalBytesSent];
2554 - [self setTotalBytesSent:[[(NSNumber *)CFReadStreamCopyProperty((CFReadStreamRef)[self readStream], kCFStreamPropertyHTTPRequestBytesWrittenCount) autorelease] unsignedLongLongValue]]; 2554 + [self setTotalBytesSent:[NSMakeCollectable([(NSNumber *)CFReadStreamCopyProperty((CFReadStreamRef)[self readStream], kCFStreamPropertyHTTPRequestBytesWrittenCount) autorelease]) unsignedLongLongValue]];
2555 [self setComplete:YES]; 2555 [self setComplete:YES];
2556 [self updateProgressIndicators]; 2556 [self updateProgressIndicators];
2557 2557
@@ -2636,6 +2636,17 @@ static BOOL isiPhoneOS2; @@ -2636,6 +2636,17 @@ static BOOL isiPhoneOS2;
2636 - (void)markAsFinished 2636 - (void)markAsFinished
2637 { 2637 {
2638 [[self retain] autorelease]; 2638 [[self retain] autorelease];
  2639 +
  2640 + // release won't be called when running with GC, so we'll clean these up now
  2641 + if (request) {
  2642 + CFMakeCollectable(request);
  2643 + }
  2644 + if (requestAuthentication) {
  2645 + CFMakeCollectable(requestAuthentication);
  2646 + }
  2647 + if (proxyAuthentication) {
  2648 + CFMakeCollectable(proxyAuthentication);
  2649 + }
2639 [self willChangeValueForKey:@"isFinished"]; 2650 [self willChangeValueForKey:@"isFinished"];
2640 [self setInProgress:NO]; 2651 [self setInProgress:NO];
2641 [self didChangeValueForKey:@"isFinished"]; 2652 [self didChangeValueForKey:@"isFinished"];
@@ -2666,7 +2677,7 @@ static BOOL isiPhoneOS2; @@ -2666,7 +2677,7 @@ static BOOL isiPhoneOS2;
2666 - (void)handleStreamError 2677 - (void)handleStreamError
2667 2678
2668 { 2679 {
2669 - NSError *underlyingError = [(NSError *)CFReadStreamCopyError((CFReadStreamRef)[self readStream]) autorelease]; 2680 + NSError *underlyingError = NSMakeCollectable([(NSError *)CFReadStreamCopyError((CFReadStreamRef)[self readStream]) autorelease]);
2670 2681
2671 [self cancelLoad]; 2682 [self cancelLoad];
2672 2683
@@ -3393,10 +3404,10 @@ static BOOL isiPhoneOS2; @@ -3393,10 +3404,10 @@ static BOOL isiPhoneOS2;
3393 } 3404 }
3394 // Obtain the list of proxies by running the autoconfiguration script 3405 // Obtain the list of proxies by running the autoconfiguration script
3395 #if TARGET_IPHONE_SIMULATOR && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_3_0 3406 #if TARGET_IPHONE_SIMULATOR && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_3_0
3396 - NSArray *proxies = [(NSArray *)CFNetworkCopyProxiesForAutoConfigurationScript((CFStringRef)script,(CFURLRef)theURL) autorelease]; 3407 + NSArray *proxies = NSMakeCollectable([(NSArray *)CFNetworkCopyProxiesForAutoConfigurationScript((CFStringRef)script,(CFURLRef)theURL) autorelease]);
3397 #else 3408 #else
3398 CFErrorRef err2 = NULL; 3409 CFErrorRef err2 = NULL;
3399 - NSArray *proxies = [(NSArray *)CFNetworkCopyProxiesForAutoConfigurationScript((CFStringRef)script,(CFURLRef)theURL, &err2) autorelease]; 3410 + NSArray *proxies = NSMakeCollectable([(NSArray *)CFNetworkCopyProxiesForAutoConfigurationScript((CFStringRef)script,(CFURLRef)theURL, &err2) autorelease]);
3400 if (err2) { 3411 if (err2) {
3401 return nil; 3412 return nil;
3402 } 3413 }
@@ -3420,7 +3431,7 @@ static BOOL isiPhoneOS2; @@ -3420,7 +3431,7 @@ static BOOL isiPhoneOS2;
3420 if (!MIMEType) { 3431 if (!MIMEType) {
3421 return @"application/octet-stream"; 3432 return @"application/octet-stream";
3422 } 3433 }
3423 - return [(NSString *)MIMEType autorelease]; 3434 + return NSMakeCollectable([(NSString *)MIMEType autorelease]);
3424 } 3435 }
3425 3436
3426 #pragma mark bandwidth measurement / throttling 3437 #pragma mark bandwidth measurement / throttling
This diff was suppressed by a .gitattributes entry.