summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-09-21 13:07:22 +0100
committerBram Moolenaar <Bram@vim.org>2022-09-21 13:07:22 +0100
commit8ecfa2c56b4992c7f067b92488aa9acea5a454ad (patch)
treef79aedf5dddb4c60237419c1f18b8e3b2ca09a9d
parent8eaee1fa5c0ce474132a04e1b70b73c49c41cc45 (diff)
patch 9.0.0530: using freed memory when autocmd changes markv9.0.0530
Problem: Using freed memory when autocmd changes mark. Solution: Copy the mark before editing another buffer.
-rw-r--r--src/mark.c12
-rw-r--r--src/testdir/test_marks.vim13
-rw-r--r--src/version.c2
3 files changed, 22 insertions, 5 deletions
diff --git a/src/mark.c b/src/mark.c
index ade5a1087b..584db033d3 100644
--- a/src/mark.c
+++ b/src/mark.c
@@ -221,17 +221,19 @@ movemark(int count)
fname2fnum(jmp);
if (jmp->fmark.fnum != curbuf->b_fnum)
{
- // jump to other file
- if (buflist_findnr(jmp->fmark.fnum) == NULL)
+ // 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(jmp->fmark.fnum, jmp->fmark.mark.lnum,
- 0, FALSE) == FAIL)
+ 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 = jmp->fmark.mark;
+ curwin->w_cursor = fmark.mark;
pos = (pos_T *)-1;
}
else
diff --git a/src/testdir/test_marks.vim b/src/testdir/test_marks.vim
index 12501a3aba..20fb3041f2 100644
--- a/src/testdir/test_marks.vim
+++ b/src/testdir/test_marks.vim
@@ -305,4 +305,17 @@ func Test_getmarklist()
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
diff --git a/src/version.c b/src/version.c
index 555adf57e0..cefa82a337 100644
--- a/src/version.c
+++ b/src/version.c
@@ -700,6 +700,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 530,
+/**/
529,
/**/
528,