patch 8.0.0923: crash in GUI when terminal job exits

Problem:    Crash in GUI when terminal job exits. (Kazunobu Kuriyama)
Solution:   reset in_terminal_loop when a terminal is freed.
diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim
index 4de853a..3ca638a 100644
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -414,3 +414,23 @@
 
   exe buf . 'bwipe'
 endfunc
+
+" must be last, we can't go back from GUI to terminal
+func Test_zz_terminal_in_gui()
+  if !has('gui')
+    return
+  endif
+  gui -f
+
+  call assert_equal(1, winnr('$'))
+  let buf = Run_shell_in_terminal({'term_finish': 'close'})
+  call Stop_shell_in_terminal(buf)
+  call term_wait(buf)
+
+  " closing window wipes out the terminal buffer a with finished job
+  call WaitFor("winnr('$') == 1")
+  call assert_equal(1, winnr('$'))
+  call assert_equal("", bufname(buf))
+
+  unlet g:job
+endfunc