Never pass an invalid X connection descriptor to an input reading loop

Fixes: debbugs:19147

* xterm.c (x_delete_terminal): Call emacs_close for X connection
descriptor if called from x_connection_closed and always delete
this descriptor from keyboard waiting set (Bug#19147).