patch 8.1.0016: possible crash in term_wait()

Problem:    Possible crash in term_wait(). (Dominique Pelle)
Solution:   Check for a valid buffer after ui_delay(). (closes #2944)
diff --git a/src/terminal.c b/src/terminal.c
index 817e6b9..6967df7 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -5264,11 +5264,11 @@
 	{
 	    mch_check_messages();
 	    parse_queued_messages();
+	    ui_delay(10L, FALSE);
 	    if (!buf_valid(buf))
 		/* If the terminal is closed when the channel is closed the
 		 * buffer disappears. */
 		break;
-	    ui_delay(10L, FALSE);
 	}
 	mch_check_messages();
 	parse_queued_messages();
diff --git a/src/version.c b/src/version.c
index d1a75a1..7d941bb 100644
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    16,
+/**/
     15,
 /**/
     14,