From 42ad967d68137df1a80a877e7b5ad56403fc157f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 25 Jun 2022 23:40:26 +0200 Subject: [PATCH] crypto: use ByteSource::Builder in To*Copy Avoid manual calls to MallocOpenSSL in ArrayBufferOrViewContents and use the new ByteSource::Builder instead. Refs: https://github.com/nodejs/node/pull/43202 PR-URL: https://github.com/nodejs/node/pull/43477 Reviewed-By: Darshan Sen --- src/crypto/crypto_util.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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