Fix double close of file descriptor (bug #1473)