To: vim_dev@googlegroups.com Subject: Patch 9.0.0530 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0530 Problem: Using freed memory when autocmd changes mark. Solution: Copy the mark before editing another buffer. Files: src/mark.c, src/testdir/test_marks.vim *** ../vim-9.0.0529/src/mark.c 2022-06-16 11:32:39.000000000 +0100 --- src/mark.c 2022-09-21 13:05:15.908543070 +0100 *************** *** 221,237 **** fname2fnum(jmp); if (jmp->fmark.fnum != curbuf->b_fnum) { ! // jump to other file ! if (buflist_findnr(jmp->fmark.fnum) == NULL) { // Skip this one .. count += count < 0 ? -1 : 1; continue; } ! if (buflist_getfile(jmp->fmark.fnum, jmp->fmark.mark.lnum, ! 0, FALSE) == FAIL) return (pos_T *)NULL; // Set lnum again, autocommands my have changed it ! curwin->w_cursor = jmp->fmark.mark; pos = (pos_T *)-1; } else --- 221,239 ---- fname2fnum(jmp); if (jmp->fmark.fnum != curbuf->b_fnum) { ! // Make a copy, an autocommand may make "jmp" invalid. ! fmark_T fmark = jmp->fmark; ! ! // jump to the file with the mark ! if (buflist_findnr(fmark.fnum) == NULL) { // Skip this one .. count += count < 0 ? -1 : 1; continue; } ! if (buflist_getfile(fmark.fnum, fmark.mark.lnum, 0, FALSE) == FAIL) return (pos_T *)NULL; // Set lnum again, autocommands my have changed it ! curwin->w_cursor = fmark.mark; pos = (pos_T *)-1; } else *** ../vim-9.0.0529/src/testdir/test_marks.vim 2021-10-17 21:46:49.000000000 +0100 --- src/testdir/test_marks.vim 2022-09-21 13:01:53.158220086 +0100 *************** *** 305,308 **** --- 305,321 ---- close! endfunc + " This was using freed memory + func Test_jump_mark_autocmd() + next 00 + edit 0 + sargument + au BufEnter 0 all + sil norm  + + au! BufEnter + bwipe! + endfunc + + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-9.0.0529/src/version.c 2022-09-21 12:19:41.612159067 +0100 --- src/version.c 2022-09-21 13:03:06.423194363 +0100 *************** *** 701,702 **** --- 701,704 ---- { /* Add new patch number below this line */ + /**/ + 530, /**/ -- hundred-and-one symptoms of being an internet addict: 121. You ask for e-mail adresses instead of telephone numbers. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///