diff --git a/src/kits/network/libnetapi/DataRequest.cpp b/src/kits/network/libnetapi/DataRequest.cpp index 6afd33c10b..a9ece68851 100644 --- a/src/kits/network/libnetapi/DataRequest.cpp +++ b/src/kits/network/libnetapi/DataRequest.cpp @@ -9,6 +9,7 @@ #include "DataRequest.h" +#include #include #include #include @@ -88,6 +89,7 @@ BDataRequest::_ProtocolLoop() } + ArrayDeleter buffer; if (isBase64) { // Check that the base64 data is properly padded (we process characters // by groups of 4 and there must not be stray chars at the end as @@ -95,18 +97,17 @@ BDataRequest::_ProtocolLoop() if (data.Length() & 3) return B_BAD_DATA; - char* buffer = new char[data.Length() * 3 / 4]; - payload = buffer; + buffer.SetTo(new char[data.Length() * 3 / 4]); + payload = buffer.Get(); // payload must be a const char* so we can assign data.String() to // it below, but decode_64 modifies buffer. - length = decode_base64(buffer, data.String(), data.Length()); + length = decode_base64(buffer.Get(), data.String(), data.Length()); // There may be some padding at the end of the base64 stream. This // prevents us from computing the exact length we should get, so allow // for some error margin. if (length > data.Length() * 3 / 4 || length < data.Length() * 3 / 4 - 3) { - delete[] buffer; return B_BAD_DATA; } } else { @@ -124,8 +125,5 @@ BDataRequest::_ProtocolLoop() } } - if (isBase64) - delete[] payload; - return B_OK; }