joyent/node — pull request #7499 by shigeki (2014-04-22 15:44:47+00:00)
Title: child_process: fix assertion error in spawnSync

This is easy to reproduce in my Ubuntu 14.04 of kernel-3.13.0-24 as
```javascript
var spawnSync = require('child_process').spawnSync;
var ret = spawnSync('command_does_not_exit');
console.log(ret.error)
````
The following assertion error occurred.
```sh
$ node ~/test.js
node: ../src/spawn_sync.cc:521: void node::SyncProcessRunner::CloseHandlesAndDeleteLoop(): Assertion `(uv_loop_close(uv_loop_)) == (0)' failed.
Aborted (core dumped)
````
It seems that `SIGCHILD` is not received in the parent in case of an error in the child so that ExitCallback is not called. This patch checks if the process handle is refed, then close it. The result is
````sh
$ ./node ~/test.js
{ [Error: spawnSync ENOENT] code: 'ENOENT', errno: 'ENOENT', syscall: 'spawnSync' }
````
I've not tested that this works well in other OSes.