Correctly close open pipes after use

* Should fix https://github.com/jonleighton/poltergeist/issues/310