Ensure open file handles are closed again.

This fixes a "Error: EMFILE, too many open files" error we've been seeing.
Merge pull request #658 from arthurschreiber/arthur/fix-too-many-open-files

Ensure open file handles are closed again.