0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.5079: DirChanged autocommand may use freed memory

Problem:    DirChanged autocommand may use freed memory. (Shane-XB Qian)
Solution:   Free the memory later. (closes #10555)
This commit is contained in:
Bram Moolenaar
2022-06-12 11:49:16 +01:00
parent 3269efdf01
commit d8c9d32c89
3 changed files with 12 additions and 1 deletions

View File

@@ -7525,6 +7525,7 @@ changedir_func(
int dir_differs;
char_u *acmd_fname = NULL;
char_u **pp;
char_u *tofree;
if (new_dir == NULL || allbuf_locked())
return FALSE;
@@ -7601,13 +7602,14 @@ changedir_func(
pp = &curtab->tp_prevdir;
else
pp = &prev_dir;
vim_free(*pp);
tofree = *pp; // new_dir may use this
*pp = pdir;
post_chdir(scope);
if (dir_differs)
apply_autocmds(EVENT_DIRCHANGED, acmd_fname, new_dir, FALSE, curbuf);
vim_free(tofree);
return TRUE;
}

View File

@@ -2107,6 +2107,13 @@ function Test_dirchanged_global()
call assert_equal(expected, s:li)
exe 'lcd ' .. fnameescape(s:dir_bar)
call assert_equal(expected, s:li)
exe 'cd ' .. s:dir_foo
exe 'cd ' .. s:dir_bar
autocmd! test_dirchanged DirChanged global let g:result = expand("<afile>")
cd -
call assert_equal(s:dir_foo, g:result)
call s:After_test_dirchanged()
endfunc

View File

@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
5079,
/**/
5078,
/**/