Browse Source

child_process: fix segfault after failed spawn

The process handle is uninitialized when uv_spawn() fails so don't export the
handle to JS land when that happens. Attempts to close the uninitialized handle
resulted in segmentation faults and memory corruption.

Fixes #2481.
v0.7.4-release
Ben Noordhuis 13 years ago
parent
commit
b07acb3808
  1. 14
      src/process_wrap.cc

14
src/process_wrap.cc

@ -177,10 +177,14 @@ class ProcessWrap : public HandleWrap {
int r = uv_spawn(uv_default_loop(), &wrap->process_, options);
wrap->SetHandle((uv_handle_t*)&wrap->process_);
assert(wrap->process_.data == wrap);
wrap->object_->Set(String::New("pid"), Integer::New(wrap->process_.pid));
if (r) {
SetErrno(uv_last_error(uv_default_loop()));
}
else {
wrap->SetHandle((uv_handle_t*)&wrap->process_);
assert(wrap->process_.data == wrap);
wrap->object_->Set(String::New("pid"), Integer::New(wrap->process_.pid));
}
if (options.args) {
for (int i = 0; options.args[i]; i++) free(options.args[i]);
@ -195,8 +199,6 @@ class ProcessWrap : public HandleWrap {
delete [] options.env;
}
if (r) SetErrno(uv_last_error(uv_default_loop()));
return scope.Close(Integer::New(r));
}

Loading…
Cancel
Save