patch 8.2.0082: when reusing a buffer listeners are not cleared

Problem:    When reusing a buffer listeners are not cleared. (Axel Forsman)
Solution:   Clear listeners when reusing a buffer. (closes #5431)
diff --git a/src/buffer.c b/src/buffer.c
index eb6b287..0a68d48 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -979,6 +979,7 @@
 	hash_init(&buf->b_vars->dv_hashtab);
 	init_changedtick(buf);
 	CHANGEDTICK(buf) = tick;
+	remove_listeners(buf);
     }
 #endif
     uc_clear(&buf->b_ucmds);		// clear local user commands
diff --git a/src/testdir/test_listener.vim b/src/testdir/test_listener.vim
index a7815dc..a263aba 100644
--- a/src/testdir/test_listener.vim
+++ b/src/testdir/test_listener.vim
@@ -295,3 +295,34 @@
   delfunc EchoChanges
   call listener_remove(lid)
 endfunc
+
+func Test_listener_cleared_newbuf()
+  func Listener(bufnr, start, end, added, changes)
+    let g:gotCalled += 1
+  endfunc
+  new
+  " check that listening works
+  let g:gotCalled = 0
+  let lid = listener_add("Listener")
+  call feedkeys("axxx\<Esc>", 'xt')
+  call listener_flush(bufnr())
+  call assert_equal(1, g:gotCalled)
+  %bwipe!
+  let bufnr = bufnr()
+  let b:testing = 123
+  let lid = listener_add("Listener")
+  enew!
+  " check buffer is reused
+  call assert_equal(bufnr, bufnr())
+  call assert_false(exists('b:testing'))
+
+  " check that listening stops when reusing the buffer
+  let g:gotCalled = 0
+  call feedkeys("axxx\<Esc>", 'xt')
+  call listener_flush(bufnr())
+  call assert_equal(0, g:gotCalled)
+  unlet g:gotCalled
+
+  bwipe!
+  delfunc Listener
+endfunc
diff --git a/src/version.c b/src/version.c
index cff754f..6dd07bb 100644
--- a/src/version.c
+++ b/src/version.c
@@ -743,6 +743,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    82,
+/**/
     81,
 /**/
     80,