setting the fd to -1 before checking for `close` errors