Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
child_process: fix segfault after failed spawn
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bnoordhuis committed Jan 9, 2012
1 parent d5d043f commit b07acb3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/process_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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));
}

Expand Down

0 comments on commit b07acb3

Please sign in to comment.