Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed crash when stub with very long data and no delay for response (continued) #59

Merged
merged 2 commits into from May 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion OHHTTPStubs/Sources/OHHTTPStubs.m
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ - (void) streamDataForClient:(id<NSURLProtocolClient>)client
timingInfo:timingInfo completion:completion];
});
} else {
uint8_t buffer[chunkSizeToRead];
uint8_t* buffer = (uint8_t*)malloc(sizeof(uint8_t*)*chunkSizeToRead);
NSInteger bytesRead = [inputStream read:buffer maxLength:chunkSizeToRead];
if (bytesRead > 0)
{
Expand All @@ -492,6 +492,7 @@ - (void) streamDataForClient:(id<NSURLProtocolClient>)client
completion(inputStream.streamError);
}
}
free(buffer);
}
}
else
Expand Down
12 changes: 12 additions & 0 deletions OHHTTPStubs/UnitTests/Test Suites/TimingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,16 @@ -(void)test_LongData_RequestTime1_ResponseTime5
[self _testWithData:testData requestTime:1 responseTime:5];
}

-(void)test_VeryLongData_RequestTime1_ResponseTime0
{
static NSUInteger const kDataLength = 609792;
NSMutableData* testData = [NSMutableData dataWithCapacity:kDataLength];
NSData* chunk = [[NSProcessInfo.processInfo globallyUniqueString] dataUsingEncoding:NSUTF8StringEncoding];
while(testData.length<kDataLength)
{
[testData appendData:chunk];
}
[self _testWithData:testData requestTime:1 responseTime:0];
}

@end