tls: preallocate SSL cipher array

PR-URL: https://github.com/nodejs/node/pull/22136
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Tobias Nießen 2018-08-05 12:17:35 +02:00
parent 8e1b6e7718
commit 4253e5583b
No known key found for this signature in database
GPG Key ID: 718207F8FD156B70

View File

@ -4850,10 +4850,11 @@ void GetSSLCiphers(const FunctionCallbackInfo<Value>& args) {
SSLPointer ssl(SSL_new(ctx.get()));
CHECK(ssl);
Local<Array> arr = Array::New(env->isolate());
STACK_OF(SSL_CIPHER)* ciphers = SSL_get_ciphers(ssl.get());
int n = sk_SSL_CIPHER_num(ciphers);
Local<Array> 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,