From b1a9cf756b06e6491c386186b7a929dbf550f5be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 5 Aug 2018 12:17:35 +0200 Subject: [PATCH] tls: preallocate SSL cipher array PR-URL: https://github.com/nodejs/node/pull/22136 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Matteo Collina --- src/node_crypto.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index c7b8c218b88af3..ce1be1e83ac092 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -4835,10 +4835,11 @@ void GetSSLCiphers(const FunctionCallbackInfo& args) { SSLPointer ssl(SSL_new(ctx.get())); CHECK(ssl); - Local arr = Array::New(env->isolate()); STACK_OF(SSL_CIPHER)* ciphers = SSL_get_ciphers(ssl.get()); + int n = sk_SSL_CIPHER_num(ciphers); + Local arr = Array::New(env->isolate(), n); - for (int i = 0; i < sk_SSL_CIPHER_num(ciphers); ++i) { + for (int i = 0; i < n; ++i) { const SSL_CIPHER* cipher = sk_SSL_CIPHER_value(ciphers, i); arr->Set(env->context(), i,