HttpRequest: Use an ArrayDeleter to manage the temporary buffer
This make sure that the temporary buffer will always be deleted should any premature return happens. Change-Id: I448ec7c3f3eeca1ef2b6473b49323f34bcb7bf86 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3077 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
@@ -575,6 +575,7 @@ BHttpRequest::_MakeRequest()
|
|||||||
size_t previousBufferSize = 0;
|
size_t previousBufferSize = 0;
|
||||||
off_t bytesUnpacked = 0;
|
off_t bytesUnpacked = 0;
|
||||||
char* inputTempBuffer = new(std::nothrow) char[kHttpBufferSize];
|
char* inputTempBuffer = new(std::nothrow) char[kHttpBufferSize];
|
||||||
|
ArrayDeleter<char> inputTempBufferDeleter(inputTempBuffer);
|
||||||
ssize_t inputTempSize = kHttpBufferSize;
|
ssize_t inputTempSize = kHttpBufferSize;
|
||||||
ssize_t chunkSize = -1;
|
ssize_t chunkSize = -1;
|
||||||
DynamicBuffer decompressorStorage;
|
DynamicBuffer decompressorStorage;
|
||||||
@@ -664,10 +665,10 @@ BHttpRequest::_MakeRequest()
|
|||||||
// 2 more bytes to handle the closing CR+LF
|
// 2 more bytes to handle the closing CR+LF
|
||||||
bytesRead = chunkSize;
|
bytesRead = chunkSize;
|
||||||
if (inputTempSize < chunkSize + 2) {
|
if (inputTempSize < chunkSize + 2) {
|
||||||
delete[] inputTempBuffer;
|
|
||||||
inputTempSize = chunkSize + 2;
|
inputTempSize = chunkSize + 2;
|
||||||
inputTempBuffer
|
inputTempBuffer
|
||||||
= new(std::nothrow) char[inputTempSize];
|
= new(std::nothrow) char[inputTempSize];
|
||||||
|
inputTempBufferDeleter.SetTo(inputTempBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputTempBuffer == NULL) {
|
if (inputTempBuffer == NULL) {
|
||||||
@@ -715,8 +716,8 @@ BHttpRequest::_MakeRequest()
|
|||||||
if (bytesRead > 0) {
|
if (bytesRead > 0) {
|
||||||
if (inputTempSize < bytesRead) {
|
if (inputTempSize < bytesRead) {
|
||||||
inputTempSize = bytesRead;
|
inputTempSize = bytesRead;
|
||||||
delete[] inputTempBuffer;
|
|
||||||
inputTempBuffer = new(std::nothrow) char[bytesRead];
|
inputTempBuffer = new(std::nothrow) char[bytesRead];
|
||||||
|
inputTempBufferDeleter.SetTo(inputTempBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputTempBuffer == NULL) {
|
if (inputTempBuffer == NULL) {
|
||||||
@@ -781,7 +782,6 @@ BHttpRequest::_MakeRequest()
|
|||||||
}
|
}
|
||||||
|
|
||||||
fSocket->Disconnect();
|
fSocket->Disconnect();
|
||||||
delete[] inputTempBuffer;
|
|
||||||
|
|
||||||
if (readError != B_OK)
|
if (readError != B_OK)
|
||||||
return readError;
|
return readError;
|
||||||
|
|||||||
Reference in New Issue
Block a user