Clear fd after closing to avoid double-close error