@@ -1021,12 +1021,12 @@ int SecureContext::TicketKeyCallback(SSL* ssl,
1021
1021
Context::Scope context_scope (env->context ());
1022
1022
1023
1023
Local<Value> argv[] = {
1024
- Buffer::New (env,
1025
- reinterpret_cast <char *>(name),
1026
- kTicketPartSize ).ToLocalChecked (),
1027
- Buffer::New (env,
1028
- reinterpret_cast <char *>(iv),
1029
- kTicketPartSize ).ToLocalChecked (),
1024
+ Buffer::Copy (env,
1025
+ reinterpret_cast <char *>(name),
1026
+ kTicketPartSize ).ToLocalChecked (),
1027
+ Buffer::Copy (env,
1028
+ reinterpret_cast <char *>(iv),
1029
+ kTicketPartSize ).ToLocalChecked (),
1030
1030
Boolean::New (env->isolate (), enc != 0 )
1031
1031
};
1032
1032
Local<Value> ret = node::MakeCallback (env,
@@ -1219,7 +1219,7 @@ int SSLWrap<Base>::NewSessionCallback(SSL* s, SSL_SESSION* sess) {
1219
1219
memset (serialized, 0 , size);
1220
1220
i2d_SSL_SESSION (sess, &serialized);
1221
1221
1222
- Local<Object> session = Buffer::New (
1222
+ Local<Object> session = Buffer::Copy (
1223
1223
env,
1224
1224
reinterpret_cast <char *>(sess->session_id ),
1225
1225
sess->session_id_length ).ToLocalChecked ();
@@ -1240,7 +1240,7 @@ void SSLWrap<Base>::OnClientHello(void* arg,
1240
1240
Context::Scope context_scope (env->context ());
1241
1241
1242
1242
Local<Object> hello_obj = Object::New (env->isolate ());
1243
- Local<Object> buff = Buffer::New (
1243
+ Local<Object> buff = Buffer::Copy (
1244
1244
env,
1245
1245
reinterpret_cast <const char *>(hello.session_id ()),
1246
1246
hello.session_size ()).ToLocalChecked ();
@@ -1701,7 +1701,7 @@ void SSLWrap<Base>::GetTLSTicket(const FunctionCallbackInfo<Value>& args) {
1701
1701
if (sess == nullptr || sess->tlsext_tick == nullptr )
1702
1702
return ;
1703
1703
1704
- Local<Object> buff = Buffer::New (
1704
+ Local<Object> buff = Buffer::Copy (
1705
1705
env,
1706
1706
reinterpret_cast <char *>(sess->tlsext_tick ),
1707
1707
sess->tlsext_ticklen ).ToLocalChecked ();
@@ -1983,7 +1983,7 @@ int SSLWrap<Base>::TLSExtStatusCallback(SSL* s, void* arg) {
1983
1983
if (resp == nullptr ) {
1984
1984
arg = Null (env->isolate ());
1985
1985
} else {
1986
- arg = Buffer::New (
1986
+ arg = Buffer::Copy (
1987
1987
env,
1988
1988
reinterpret_cast <char *>(const_cast <unsigned char *>(resp)),
1989
1989
len).ToLocalChecked ();
@@ -2989,7 +2989,8 @@ bool CipherBase::GetAuthTag(char** out, unsigned int* out_len) const {
2989
2989
if (initialised_ || kind_ != kCipher || !auth_tag_)
2990
2990
return false ;
2991
2991
*out_len = auth_tag_len_;
2992
- *out = new char [auth_tag_len_];
2992
+ *out = static_cast <char *>(malloc (auth_tag_len_));
2993
+ CHECK_NE (*out, nullptr );
2993
2994
memcpy (*out, auth_tag_, auth_tag_len_);
2994
2995
return true ;
2995
2996
}
@@ -3003,7 +3004,7 @@ void CipherBase::GetAuthTag(const FunctionCallbackInfo<Value>& args) {
3003
3004
unsigned int out_len = 0 ;
3004
3005
3005
3006
if (cipher->GetAuthTag (&out, &out_len)) {
3006
- Local<Object> buf = Buffer::New (env, out, out_len).ToLocalChecked ();
3007
+ Local<Object> buf = Buffer::Use (env, out, out_len).ToLocalChecked ();
3007
3008
args.GetReturnValue ().Set (buf);
3008
3009
} else {
3009
3010
env->ThrowError (" Attempting to get auth tag in unsupported state" );
@@ -3120,8 +3121,9 @@ void CipherBase::Update(const FunctionCallbackInfo<Value>& args) {
3120
3121
" Trying to add data in unsupported state" );
3121
3122
}
3122
3123
3124
+ CHECK (out != nullptr || out_len == 0 );
3123
3125
Local<Object> buf =
3124
- Buffer::New (env, reinterpret_cast <char *>(out), out_len).ToLocalChecked ();
3126
+ Buffer::Copy (env, reinterpret_cast <char *>(out), out_len).ToLocalChecked ();
3125
3127
if (out)
3126
3128
delete[] out;
3127
3129
@@ -3196,7 +3198,7 @@ void CipherBase::Final(const FunctionCallbackInfo<Value>& args) {
3196
3198
}
3197
3199
}
3198
3200
3199
- Local<Object> buf = Buffer::New (
3201
+ Local<Object> buf = Buffer::Copy (
3200
3202
env,
3201
3203
reinterpret_cast <char *>(out_value),
3202
3204
out_len).ToLocalChecked ();
@@ -3978,7 +3980,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
3978
3980
}
3979
3981
}
3980
3982
3981
- Local<Object> vbuf = Buffer::New (
3983
+ Local<Object> vbuf = Buffer::Copy (
3982
3984
env,
3983
3985
reinterpret_cast <char *>(out_value),
3984
3986
out_len).ToLocalChecked ();
@@ -4515,7 +4517,7 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) {
4515
4517
}
4516
4518
4517
4519
Local<Object> buf =
4518
- Buffer::New (env, reinterpret_cast <char *>(out), size).ToLocalChecked ();
4520
+ Buffer::Use (env, reinterpret_cast <char *>(out), size).ToLocalChecked ();
4519
4521
args.GetReturnValue ().Set (buf);
4520
4522
}
4521
4523
0 commit comments