make sure the fd is valid before accessing it