@@ -5534,9 +5534,9 @@ void PBKDF2Request::After() {
5534
5534
5535
5535
void PBKDF2Request::After (uv_work_t * work_req, int status) {
5536
5536
CHECK_EQ (status, 0 );
5537
- PBKDF2Request* req = ContainerOf (&PBKDF2Request::work_req_, work_req);
5537
+ std::unique_ptr<PBKDF2Request> req (
5538
+ ContainerOf (&PBKDF2Request::work_req_, work_req));
5538
5539
req->After ();
5539
- delete req;
5540
5540
}
5541
5541
5542
5542
@@ -5551,7 +5551,6 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) {
5551
5551
double raw_keylen = -1 ;
5552
5552
int keylen = -1 ;
5553
5553
int iter = -1 ;
5554
- PBKDF2Request* req = nullptr ;
5555
5554
Local<Object> obj;
5556
5555
5557
5556
passlen = Buffer::Length (args[0 ]);
@@ -5587,15 +5586,9 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) {
5587
5586
5588
5587
obj = env->pbkdf2_constructor_template ()->
5589
5588
NewInstance (env->context ()).ToLocalChecked ();
5590
- req = new PBKDF2Request (env,
5591
- obj,
5592
- digest,
5593
- passlen,
5594
- pass,
5595
- saltlen,
5596
- salt,
5597
- iter,
5598
- keylen);
5589
+ std::unique_ptr<PBKDF2Request> req (
5590
+ new PBKDF2Request (env, obj, digest, passlen, pass, saltlen, salt, iter,
5591
+ keylen));
5599
5592
5600
5593
if (args[5 ]->IsFunction ()) {
5601
5594
obj->Set (env->ondone_string (), args[5 ]);
@@ -5608,15 +5601,14 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) {
5608
5601
}
5609
5602
5610
5603
uv_queue_work (env->event_loop (),
5611
- req->work_req (),
5604
+ req. release () ->work_req (),
5612
5605
PBKDF2Request::Work,
5613
5606
PBKDF2Request::After);
5614
5607
} else {
5615
5608
env->PrintSyncTrace ();
5616
5609
req->Work ();
5617
5610
Local<Value> argv[2 ];
5618
5611
req->After (&argv);
5619
- delete req;
5620
5612
5621
5613
if (argv[0 ]->IsObject ())
5622
5614
env->isolate ()->ThrowException (argv[0 ]);
@@ -5754,25 +5746,23 @@ void RandomBytesCheck(RandomBytesRequest* req, Local<Value> (*argv)[2]) {
5754
5746
5755
5747
void RandomBytesAfter (uv_work_t * work_req, int status) {
5756
5748
CHECK_EQ (status, 0 );
5757
- RandomBytesRequest* req =
5758
- ContainerOf (&RandomBytesRequest::work_req_, work_req);
5749
+ std::unique_ptr< RandomBytesRequest> req (
5750
+ ContainerOf (&RandomBytesRequest::work_req_, work_req)) ;
5759
5751
Environment* env = req->env ();
5760
5752
HandleScope handle_scope (env->isolate ());
5761
5753
Context::Scope context_scope (env->context ());
5762
5754
Local<Value> argv[2 ];
5763
- RandomBytesCheck (req, &argv);
5755
+ RandomBytesCheck (req. get () , &argv);
5764
5756
req->MakeCallback (env->ondone_string (), arraysize (argv), argv);
5765
- delete req;
5766
5757
}
5767
5758
5768
5759
5769
5760
void RandomBytesProcessSync (Environment* env,
5770
- RandomBytesRequest* req,
5761
+ std::unique_ptr< RandomBytesRequest> req,
5771
5762
Local<Value> (*argv)[2 ]) {
5772
5763
env->PrintSyncTrace ();
5773
5764
RandomBytesWork (req->work_req ());
5774
- RandomBytesCheck (req, argv);
5775
- delete req;
5765
+ RandomBytesCheck (req.get (), argv);
5776
5766
5777
5767
if (!(*argv)[0 ]->IsNull ())
5778
5768
env->isolate ()->ThrowException ((*argv)[0 ]);
@@ -5788,12 +5778,12 @@ void RandomBytes(const FunctionCallbackInfo<Value>& args) {
5788
5778
Local<Object> obj = env->randombytes_constructor_template ()->
5789
5779
NewInstance (env->context ()).ToLocalChecked ();
5790
5780
char * data = node::Malloc (size);
5791
- RandomBytesRequest* req =
5781
+ std::unique_ptr< RandomBytesRequest> req (
5792
5782
new RandomBytesRequest (env,
5793
5783
obj,
5794
5784
size,
5795
5785
data,
5796
- RandomBytesRequest::FREE_DATA);
5786
+ RandomBytesRequest::FREE_DATA)) ;
5797
5787
5798
5788
if (args[1 ]->IsFunction ()) {
5799
5789
obj->Set (env->ondone_string (), args[1 ]);
@@ -5806,13 +5796,13 @@ void RandomBytes(const FunctionCallbackInfo<Value>& args) {
5806
5796
}
5807
5797
5808
5798
uv_queue_work (env->event_loop (),
5809
- req->work_req (),
5799
+ req. release () ->work_req (),
5810
5800
RandomBytesWork,
5811
5801
RandomBytesAfter);
5812
5802
args.GetReturnValue ().Set (obj);
5813
5803
} else {
5814
5804
Local<Value> argv[2 ];
5815
- RandomBytesProcessSync (env, req, &argv);
5805
+ RandomBytesProcessSync (env, std::move ( req) , &argv);
5816
5806
if (argv[0 ]->IsNull ())
5817
5807
args.GetReturnValue ().Set (argv[1 ]);
5818
5808
}
@@ -5835,12 +5825,12 @@ void RandomBytesBuffer(const FunctionCallbackInfo<Value>& args) {
5835
5825
char * data = Buffer::Data (args[0 ]);
5836
5826
data += offset;
5837
5827
5838
- RandomBytesRequest* req =
5828
+ std::unique_ptr< RandomBytesRequest> req (
5839
5829
new RandomBytesRequest (env,
5840
5830
obj,
5841
5831
size,
5842
5832
data,
5843
- RandomBytesRequest::DONT_FREE_DATA);
5833
+ RandomBytesRequest::DONT_FREE_DATA)) ;
5844
5834
if (args[3 ]->IsFunction ()) {
5845
5835
obj->Set (env->context (), env->ondone_string (), args[3 ]).FromJust ();
5846
5836
@@ -5852,13 +5842,13 @@ void RandomBytesBuffer(const FunctionCallbackInfo<Value>& args) {
5852
5842
}
5853
5843
5854
5844
uv_queue_work (env->event_loop (),
5855
- req->work_req (),
5845
+ req. release () ->work_req (),
5856
5846
RandomBytesWork,
5857
5847
RandomBytesAfter);
5858
5848
args.GetReturnValue ().Set (obj);
5859
5849
} else {
5860
5850
Local<Value> argv[2 ];
5861
- RandomBytesProcessSync (env, req, &argv);
5851
+ RandomBytesProcessSync (env, std::move ( req) , &argv);
5862
5852
if (argv[0 ]->IsNull ())
5863
5853
args.GetReturnValue ().Set (argv[1 ]);
5864
5854
}
0 commit comments