Fix bug that was autoclosing file descriptor