Skip to content

Commit a43928a

Browse files
tniessentargos
authored andcommitted
crypto: use ByteSource::Builder in To*Copy
Avoid manual calls to MallocOpenSSL in ArrayBufferOrViewContents and use the new ByteSource::Builder instead. Refs: #43202 PR-URL: #43477 Reviewed-By: Darshan Sen <[email protected]>
1 parent d3fc791 commit a43928a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/crypto/crypto_util.h

+7-9
Original file line numberDiff line numberDiff line change
@@ -747,19 +747,17 @@ class ArrayBufferOrViewContents {
747747

748748
inline ByteSource ToCopy() const {
749749
if (size() == 0) return ByteSource();
750-
char* buf = MallocOpenSSL<char>(size());
751-
CHECK_NOT_NULL(buf);
752-
memcpy(buf, data(), size());
753-
return ByteSource::Allocated(buf, size());
750+
ByteSource::Builder buf(size());
751+
memcpy(buf.data<void>(), data(), size());
752+
return std::move(buf).release();
754753
}
755754

756755
inline ByteSource ToNullTerminatedCopy() const {
757756
if (size() == 0) return ByteSource();
758-
char* buf = MallocOpenSSL<char>(size() + 1);
759-
CHECK_NOT_NULL(buf);
760-
buf[size()] = 0;
761-
memcpy(buf, data(), size());
762-
return ByteSource::Allocated(buf, size());
757+
ByteSource::Builder buf(size() + 1);
758+
memcpy(buf.data<void>(), data(), size());
759+
buf.data<char>()[size()] = 0;
760+
return std::move(buf).release(size());
763761
}
764762

765763
template <typename M>

0 commit comments

Comments
 (0)