From 0e6123ddce62bc2cfad4d013f41d63678c1bff59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 18 Jun 2022 16:19:39 +0000 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 --- 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 e5d9410039cad1..d46da466aaf8c8 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