This patch also fixes a potentially leaking file descriptor in error code-paths.
Closes: #24 (closed)