Skip to content

Commit

Permalink
crypto: fix memory leak in PBKDF2Request
Browse files Browse the repository at this point in the history
PR-URL: #2375
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
skomski authored and Fishrock123 committed Aug 19, 2015
1 parent ba6eb8a commit 605f6ee
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4622,6 +4622,7 @@ class PBKDF2Request : public AsyncWrap {
}

~PBKDF2Request() override {
release();
persistent().Reset();
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -4737,7 +4743,6 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) {
Local<Value> argv[2];
EIO_PBKDF2After(req, argv);
req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv);
req->release();
delete req;
}

Expand Down Expand Up @@ -4848,6 +4853,9 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) {
Local<Value> argv[2];
EIO_PBKDF2(req);
EIO_PBKDF2After(req, argv);

delete req;

if (argv[0]->IsObject())
env->isolate()->ThrowException(argv[0]);
else
Expand Down

0 comments on commit 605f6ee

Please sign in to comment.