Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix leak in setting response headers

Alter read buffer size depending on the Content-length header
  • Loading branch information...
commit 5fb6e03ba3869da776413920b3681756122ebaa6 1 parent c149467
Ben Copsey authored
Showing with 12 additions and 4 deletions.
  1. +12 −4 ASIHTTPRequest.m
16 ASIHTTPRequest.m
View
@@ -520,7 +520,7 @@ - (void)updateUploadProgress
[cancelledLock unlock];
return;
}
- unsigned long long byteCount = [[(NSNumber *)CFReadStreamCopyProperty (readStream, kCFStreamPropertyHTTPRequestBytesWrittenCount) autorelease] unsignedLongLongValue];
+ unsigned long long byteCount = [[(NSNumber *)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPRequestBytesWrittenCount) autorelease] unsignedLongLongValue];
// If this is the first time we've written to the buffer, byteCount will be the size of the buffer (currently seems to be 128KB on both Mac and iPhone)
// We will remove this from any progress display, as kCFStreamPropertyHTTPRequestBytesWrittenCount does not tell us how much data has actually be written
@@ -755,7 +755,9 @@ - (BOOL)readResponseHeadersReturningAuthenticationFailure
BOOL isAuthenticationChallenge = NO;
CFHTTPMessageRef headers = (CFHTTPMessageRef)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPResponseHeader);
if (CFHTTPMessageIsHeaderComplete(headers)) {
- [self setResponseHeaders:(NSDictionary *)CFHTTPMessageCopyAllHeaderFields(headers)];
+ CFDictionaryRef headerFields = CFHTTPMessageCopyAllHeaderFields(headers);
+ [self setResponseHeaders:(NSDictionary *)headerFields];
+ CFRelease(headerFields);
[self setResponseStatusCode:CFHTTPMessageGetResponseStatusCode(headers)];
// Is the server response a challenge for credentials?
@@ -1028,7 +1030,7 @@ - (void)attemptToApplyCredentialsAndResume
- (void)handleNetworkEvent:(CFStreamEventType)type
-{
+{
// Dispatch the stream events.
switch (type) {
case kCFStreamEventHasBytesAvailable:
@@ -1058,8 +1060,14 @@ - (void)handleBytesAvailable
return;
}
}
+ int bufferSize = 2048;
+ if (contentLength > 262144) {
+ bufferSize = 65536;
+ } else if (contentLength > 65536) {
+ bufferSize = 16384;
+ }
- UInt8 buffer[2048];
+ UInt8 buffer[bufferSize];
CFIndex bytesRead = CFReadStreamRead(readStream, buffer, sizeof(buffer));
Please sign in to comment.
Something went wrong with that request. Please try again.