diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index fb5e8fd65b7a3b..a4f38595916281 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -1804,11 +1804,10 @@ void SSLWrap::GetSession(const FunctionCallbackInfo& args) {
int slen = i2d_SSL_SESSION(sess, nullptr);
CHECK_GT(slen, 0);
- char* sbuf = new char[slen];
+ char* sbuf = Malloc(slen);
unsigned char* p = reinterpret_cast(sbuf);
i2d_SSL_SESSION(sess, &p);
- args.GetReturnValue().Set(Encode(env->isolate(), sbuf, slen, BUFFER));
- delete[] sbuf;
+ args.GetReturnValue().Set(Buffer::New(env, sbuf, slen).ToLocalChecked());
}