@@ -417,14 +417,7 @@ SyncProcessRunner::SyncProcessRunner(Environment* env)
417
417
SyncProcessRunner::~SyncProcessRunner () {
418
418
CHECK_EQ (lifecycle_, kHandlesClosed );
419
419
420
- if (stdio_pipes_ != nullptr ) {
421
- for (size_t i = 0 ; i < stdio_count_; i++) {
422
- if (stdio_pipes_[i] != nullptr )
423
- delete stdio_pipes_[i];
424
- }
425
- }
426
-
427
- delete[] stdio_pipes_;
420
+ stdio_pipes_.reset ();
428
421
delete[] file_buffer_;
429
422
delete[] args_buffer_;
430
423
delete[] cwd_buffer_;
@@ -495,7 +488,7 @@ void SyncProcessRunner::TryInitializeAndRunLoop(Local<Value> options) {
495
488
uv_process_.data = this ;
496
489
497
490
for (uint32_t i = 0 ; i < stdio_count_; i++) {
498
- SyncProcessStdioPipe* h = stdio_pipes_[i];
491
+ SyncProcessStdioPipe* h = stdio_pipes_[i]. get () ;
499
492
if (h != nullptr ) {
500
493
r = h->Start ();
501
494
if (r < 0 )
@@ -554,11 +547,11 @@ void SyncProcessRunner::CloseStdioPipes() {
554
547
CHECK_LT (lifecycle_, kHandlesClosed );
555
548
556
549
if (stdio_pipes_initialized_) {
557
- CHECK_NE (stdio_pipes_, nullptr );
550
+ CHECK (stdio_pipes_);
558
551
CHECK_NE (uv_loop_, nullptr );
559
552
560
553
for (uint32_t i = 0 ; i < stdio_count_; i++) {
561
- if (stdio_pipes_[i] != nullptr )
554
+ if (stdio_pipes_[i])
562
555
stdio_pipes_[i]->Close ();
563
556
}
564
557
@@ -711,14 +704,14 @@ Local<Object> SyncProcessRunner::BuildResultObject() {
711
704
712
705
Local<Array> SyncProcessRunner::BuildOutputArray () {
713
706
CHECK_GE (lifecycle_, kInitialized );
714
- CHECK_NE (stdio_pipes_, nullptr );
707
+ CHECK (stdio_pipes_);
715
708
716
709
EscapableHandleScope scope (env ()->isolate ());
717
710
Local<Context> context = env ()->context ();
718
711
Local<Array> js_output = Array::New (env ()->isolate (), stdio_count_);
719
712
720
713
for (uint32_t i = 0 ; i < stdio_count_; i++) {
721
- SyncProcessStdioPipe* h = stdio_pipes_[i];
714
+ SyncProcessStdioPipe* h = stdio_pipes_[i]. get () ;
722
715
if (h != nullptr && h->writable ())
723
716
js_output->Set (context, i, h->GetOutputAsBuffer (env ())).FromJust ();
724
717
else
@@ -851,7 +844,8 @@ int SyncProcessRunner::ParseStdioOptions(Local<Value> js_value) {
851
844
stdio_count_ = js_stdio_options->Length ();
852
845
uv_stdio_containers_ = new uv_stdio_container_t [stdio_count_];
853
846
854
- stdio_pipes_ = new SyncProcessStdioPipe*[stdio_count_]();
847
+ stdio_pipes_.reset (
848
+ new std::unique_ptr<SyncProcessStdioPipe>[stdio_count_]());
855
849
stdio_pipes_initialized_ = true ;
856
850
857
851
for (uint32_t i = 0 ; i < stdio_count_; i++) {
@@ -925,7 +919,7 @@ int SyncProcessRunner::ParseStdioOption(int child_fd,
925
919
926
920
int SyncProcessRunner::AddStdioIgnore (uint32_t child_fd) {
927
921
CHECK_LT (child_fd, stdio_count_);
928
- CHECK_EQ ( stdio_pipes_[child_fd], nullptr );
922
+ CHECK (! stdio_pipes_[child_fd]);
929
923
930
924
uv_stdio_containers_[child_fd].flags = UV_IGNORE;
931
925
@@ -938,31 +932,29 @@ int SyncProcessRunner::AddStdioPipe(uint32_t child_fd,
938
932
bool writable,
939
933
uv_buf_t input_buffer) {
940
934
CHECK_LT (child_fd, stdio_count_);
941
- CHECK_EQ ( stdio_pipes_[child_fd], nullptr );
935
+ CHECK (! stdio_pipes_[child_fd]);
942
936
943
- SyncProcessStdioPipe* h = new SyncProcessStdioPipe (this ,
944
- readable,
945
- writable,
946
- input_buffer);
937
+ std::unique_ptr<SyncProcessStdioPipe> h (
938
+ new SyncProcessStdioPipe (this , readable, writable, input_buffer));
947
939
948
940
int r = h->Initialize (uv_loop_);
949
941
if (r < 0 ) {
950
- delete h ;
942
+ h. reset () ;
951
943
return r;
952
944
}
953
945
954
- stdio_pipes_[child_fd] = h;
955
-
956
946
uv_stdio_containers_[child_fd].flags = h->uv_flags ();
957
947
uv_stdio_containers_[child_fd].data .stream = h->uv_stream ();
958
948
949
+ stdio_pipes_[child_fd] = std::move (h);
950
+
959
951
return 0 ;
960
952
}
961
953
962
954
963
955
int SyncProcessRunner::AddStdioInheritFD (uint32_t child_fd, int inherit_fd) {
964
956
CHECK_LT (child_fd, stdio_count_);
965
- CHECK_EQ ( stdio_pipes_[child_fd], nullptr );
957
+ CHECK (! stdio_pipes_[child_fd]);
966
958
967
959
uv_stdio_containers_[child_fd].flags = UV_INHERIT_FD;
968
960
uv_stdio_containers_[child_fd].data .fd = inherit_fd;
0 commit comments