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 <[email protected]>
  • Loading branch information
skomski authored and bnoordhuis committed Aug 17, 2015
1 parent 12ab8cf commit a40ae51
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 @@ -4624,6 +4624,7 @@ class PBKDF2Request : public AsyncWrap {
}

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

Expand Down Expand Up @@ -4665,10 +4666,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 @@ -4739,7 +4745,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 @@ -4850,6 +4855,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 a40ae51

Please sign in to comment.