Fix File descriptor leak related to GH-1324.
Merge pull request #1325 from popox/fix-gh-1324

Fix File descriptor leak related to GH-1324.