Style fixes and allocation checks

This commit is contained in:
Adrien Destugues 2014-01-17 15:05:05 +01:00
parent bb03a92ef6
commit ab390d3af3
2 changed files with 22 additions and 7 deletions

View File

@ -241,7 +241,7 @@ BHttpRequest::Result() const
status_t status_t
BHttpRequest::Stop() BHttpRequest::Stop()
{ {
if (fSocket) { if (fSocket != NULL) {
fSocket->Disconnect(); fSocket->Disconnect();
// Unlock any pending connect, read or write operation. // Unlock any pending connect, read or write operation.
} }
@ -342,7 +342,8 @@ BHttpRequest::_ProtocolLoop()
if (authentication->Method() == B_HTTP_AUTHENTICATION_NONE) { if (authentication->Method() == B_HTTP_AUTHENTICATION_NONE) {
// There is no authentication context for this // There is no authentication context for this
// url yet, so let's create one. // url yet, so let's create one.
authentication = new(std::nothrow) BHttpAuthentication(); authentication
= new(std::nothrow) BHttpAuthentication();
if (authentication == NULL) if (authentication == NULL)
status = B_NO_MEMORY; status = B_NO_MEMORY;
else { else {
@ -437,7 +438,8 @@ BHttpRequest::_MakeRequest()
if (fListener != NULL) if (fListener != NULL)
fListener->ConnectionOpened(this); fListener->ConnectionOpened(this);
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Connection opened, sending request."); _EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT,
"Connection opened, sending request.");
_SendRequest(); _SendRequest();
_SendHeaders(); _SendHeaders();
@ -610,8 +612,15 @@ BHttpRequest::_MakeRequest()
if (inputTempSize < chunkSize + 2) { if (inputTempSize < chunkSize + 2) {
delete[] inputTempBuffer; delete[] inputTempBuffer;
inputTempSize = chunkSize + 2; inputTempSize = chunkSize + 2;
inputTempBuffer = new(std::nothrow) char[inputTempSize]; inputTempBuffer
= new(std::nothrow) char[inputTempSize];
} }
if (inputTempBuffer == NULL) {
readError = B_NO_MEMORY;
break;
}
fInputBuffer.RemoveData(inputTempBuffer, fInputBuffer.RemoveData(inputTempBuffer,
chunkSize + 2); chunkSize + 2);
chunkSize = -1; chunkSize = -1;
@ -658,6 +667,11 @@ BHttpRequest::_MakeRequest()
delete[] inputTempBuffer; delete[] inputTempBuffer;
inputTempBuffer = new(std::nothrow) char[bytesRead]; inputTempBuffer = new(std::nothrow) char[bytesRead];
} }
if (inputTempBuffer == NULL) {
readError = B_NO_MEMORY;
break;
}
fInputBuffer.RemoveData(inputTempBuffer, bytesRead); fInputBuffer.RemoveData(inputTempBuffer, bytesRead);
} }
} }
@ -851,7 +865,8 @@ BHttpRequest::_SendHeaders()
fOutputHeaders.AddHeader("Content-Length", fOutputHeaders.AddHeader("Content-Length",
fOptPostFields->ContentLength()); fOptPostFields->ContentLength());
} else if (fOptInputData != NULL } else if (fOptInputData != NULL
&& (fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT)) { && (fRequestMethod == B_HTTP_POST
|| fRequestMethod == B_HTTP_PUT)) {
if (fOptInputDataSize >= 0) if (fOptInputDataSize >= 0)
fOutputHeaders.AddHeader("Content-Length", fOptInputDataSize); fOutputHeaders.AddHeader("Content-Length", fOptInputDataSize);
else else

View File

@ -147,8 +147,8 @@ BSecureSocket::Private::VerifyCallback(int ok, X509_STORE_CTX* ctx)
// we got from the server, but something higher up in the certificate // we got from the server, but something higher up in the certificate
// chain) // chain)
X509* x509 = X509_STORE_CTX_get_current_cert(ctx); X509* x509 = X509_STORE_CTX_get_current_cert(ctx);
BCertificate::Private* certificate = BCertificate::Private* certificate
new(std::nothrow) BCertificate::Private(x509); = new(std::nothrow) BCertificate::Private(x509);
if (certificate == NULL) if (certificate == NULL)
return 0; return 0;