Patch 9.0.0361
Problem:    Removing a listener may result in a memory leak and remove
            subsequent listerns.
Solution:   Init the "prev" pointer only once. (Yegappan Lakshmanan,
            closes #11039)
Files:      src/change.c, src/testdir/test_listener.vim


*** ../vim-9.0.0360/src/change.c        2022-08-25 15:11:11.396084550 +0100
--- src/change.c        2022-09-02 17:06:43.597857183 +0100
***************
*** 362,367 ****
--- 362,368 ----
      int               save_updating_screen = updating_screen;
      static int        recursive = FALSE;
      listener_T        *next;
+     listener_T        *prev;
  
      if (buf->b_recorded_changes == NULL  // nothing changed
            || buf->b_listener == NULL   // no listeners
***************
*** 406,415 ****
      }
  
      // If f_listener_remove() was called may have to remove a listener now.
      for (lnr = buf->b_listener; lnr != NULL; lnr = next)
      {
-       listener_T      *prev = NULL;
- 
        next = lnr->lr_next;
        if (lnr->lr_id == 0)
            remove_listener(buf, lnr, prev);
--- 407,415 ----
      }
  
      // If f_listener_remove() was called may have to remove a listener now.
+     prev = NULL;
      for (lnr = buf->b_listener; lnr != NULL; lnr = next)
      {
        next = lnr->lr_next;
        if (lnr->lr_id == 0)
            remove_listener(buf, lnr, prev);
*** ../vim-9.0.0360/src/testdir/test_listener.vim       2022-02-14 
14:48:37.000000000 +0000
--- src/testdir/test_listener.vim       2022-09-02 17:06:43.597857183 +0100
***************
*** 387,392 ****
--- 387,423 ----
    unlet g:listener_called
  endfunc
  
+ " When multiple listeners are registered, remove one listener and verify the
+ " other listener is still called
+ func Test_remove_one_listener_in_callback()
+   new
+   let g:listener1_called = 0
+   let g:listener2_called = 0
+   let s:ID1 = listener_add('Listener1')
+   let s:ID2 = listener_add('Listener2')
+   func Listener1(...)
+     call listener_remove(s:ID1)
+     let g:listener1_called += 1
+   endfunc
+   func Listener2(...)
+     let g:listener2_called += 1
+   endfunc
+   call setline(1, ['foo'])
+   call feedkeys("~", 'xt')
+   call listener_flush()
+   call feedkeys("~", 'xt')
+   call listener_flush()
+   call assert_equal(1, g:listener1_called)
+   call assert_equal(2, g:listener2_called)
+ 
+   call listener_remove(s:ID2)
+   bwipe!
+   delfunc Listener1
+   delfunc Listener2
+   unlet g:listener1_called
+   unlet g:listener2_called
+ endfunc
+ 
  func Test_no_change_for_empty_undo()
    new
    let text = ['some word here', 'second line']
*** ../vim-9.0.0360/src/version.c       2022-09-02 16:47:12.915042726 +0100
--- src/version.c       2022-09-02 17:08:07.677754374 +0100
***************
*** 709,710 ****
--- 709,712 ----
  {   /* Add new patch number below this line */
+ /**/
+     361,
  /**/

-- 
Team-building exercises come in many forms but they all trace their roots back
to the prison system.  In your typical team-building exercise the employees
are subjected to a variety of unpleasant situations until they become either a
cohesive team or a ring of car jackers.
                                (Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220902161259.1BA391C0BD8%40moolenaar.net.

Raspunde prin e-mail lui