From 605f6ee904ca0b5c733a31e386a287a7b589b86b Mon Sep 17 00:00:00 2001 From: Karl Skomski Date: Fri, 14 Aug 2015 14:35:41 +0200 Subject: [PATCH] crypto: fix memory leak in PBKDF2Request PR-URL: https://github.com/nodejs/node/pull/2375 Reviewed-By: Ben Noordhuis --- src/node_crypto.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 090c908894efd6..c95e0fa31d787f 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -4622,6 +4622,7 @@ class PBKDF2Request : public AsyncWrap { } ~PBKDF2Request() override { + release(); persistent().Reset(); } @@ -4663,10 +4664,15 @@ class PBKDF2Request : public AsyncWrap { inline void release() { free(pass_); + pass_ = nullptr; passlen_ = 0; + free(salt_); + salt_ = nullptr; saltlen_ = 0; + free(key_); + key_ = nullptr; keylen_ = 0; } @@ -4737,7 +4743,6 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) { Local argv[2]; EIO_PBKDF2After(req, argv); req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv); - req->release(); delete req; } @@ -4848,6 +4853,9 @@ void PBKDF2(const FunctionCallbackInfo& args) { Local argv[2]; EIO_PBKDF2(req); EIO_PBKDF2After(req, argv); + + delete req; + if (argv[0]->IsObject()) env->isolate()->ThrowException(argv[0]); else