This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

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.
  • Loading branch information...
bnoordhuis committed Jan 9, 2012
1 parent d5d043f commit b07acb38086c3ad16817743391b7520d27032b2a
Showing with 8 additions and 6 deletions.
  1. +8 −6 src/process_wrap.cc
View
@@ -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));
}

0 comments on commit b07acb3

Please sign in to comment.