diff --git a/src/crypto/crypto_util.h b/src/crypto/crypto_util.h index c0b10583ce0978..9e33b3777b00d7 100644 --- a/src/crypto/crypto_util.h +++ b/src/crypto/crypto_util.h @@ -747,19 +747,17 @@ class ArrayBufferOrViewContents { inline ByteSource ToCopy() const { if (size() == 0) return ByteSource(); - char* buf = MallocOpenSSL(size()); - CHECK_NOT_NULL(buf); - memcpy(buf, data(), size()); - return ByteSource::Allocated(buf, size()); + ByteSource::Builder buf(size()); + memcpy(buf.data(), data(), size()); + return std::move(buf).release(); } inline ByteSource ToNullTerminatedCopy() const { if (size() == 0) return ByteSource(); - char* buf = MallocOpenSSL(size() + 1); - CHECK_NOT_NULL(buf); - buf[size()] = 0; - memcpy(buf, data(), size()); - return ByteSource::Allocated(buf, size()); + ByteSource::Builder buf(size() + 1); + memcpy(buf.data(), data(), size()); + buf.data()[size()] = 0; + return std::move(buf).release(size()); } template