mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Problem: Memory leak when using :mkview with a terminal buffer. Solution: Don't use a hastab for :mkview. (Rob Pilling, closes #6935)
This commit is contained in:
@@ -305,12 +305,10 @@ put_view(
|
|||||||
win_T *wp,
|
win_T *wp,
|
||||||
int add_edit, // add ":edit" command to view
|
int add_edit, // add ":edit" command to view
|
||||||
unsigned *flagp, // vop_flags or ssop_flags
|
unsigned *flagp, // vop_flags or ssop_flags
|
||||||
int current_arg_idx // current argument index of the window, use
|
int current_arg_idx, // current argument index of the window,
|
||||||
// -1 if unknown
|
// use -1 if unknown
|
||||||
#ifdef FEAT_TERMINAL
|
hashtab_T *terminal_bufs UNUSED) // already encountered terminal buffers,
|
||||||
, hashtab_T *terminal_bufs
|
// can be NULL
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
win_T *save_curwin;
|
win_T *save_curwin;
|
||||||
int f;
|
int f;
|
||||||
@@ -825,9 +823,11 @@ makeopens(
|
|||||||
{
|
{
|
||||||
if (!ses_do_win(wp))
|
if (!ses_do_win(wp))
|
||||||
continue;
|
continue;
|
||||||
if (put_view(fd, wp, wp != edited_win, &ssop_flags, cur_arg_idx
|
if (put_view(fd, wp, wp != edited_win, &ssop_flags, cur_arg_idx,
|
||||||
#ifdef FEAT_TERMINAL
|
#ifdef FEAT_TERMINAL
|
||||||
, &terminal_bufs
|
&terminal_bufs
|
||||||
|
#else
|
||||||
|
NULL
|
||||||
#endif
|
#endif
|
||||||
) == FAIL)
|
) == FAIL)
|
||||||
goto fail;
|
goto fail;
|
||||||
@@ -1102,11 +1102,6 @@ ex_mkrc(exarg_T *eap)
|
|||||||
char_u *viewFile = NULL;
|
char_u *viewFile = NULL;
|
||||||
unsigned *flagp;
|
unsigned *flagp;
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEAT_TERMINAL
|
|
||||||
hashtab_T terminal_bufs;
|
|
||||||
|
|
||||||
hash_init(&terminal_bufs);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (eap->cmdidx == CMD_mksession || eap->cmdidx == CMD_mkview)
|
if (eap->cmdidx == CMD_mksession || eap->cmdidx == CMD_mkview)
|
||||||
{
|
{
|
||||||
@@ -1263,11 +1258,8 @@ ex_mkrc(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
failed |= (put_view(fd, curwin, !using_vdir, flagp, -1
|
failed |= (put_view(fd, curwin, !using_vdir, flagp, -1, NULL)
|
||||||
#ifdef FEAT_TERMINAL
|
== FAIL);
|
||||||
, &terminal_bufs
|
|
||||||
#endif
|
|
||||||
) == FAIL);
|
|
||||||
}
|
}
|
||||||
if (put_line(fd, "let &so = s:so_save | let &siso = s:siso_save")
|
if (put_line(fd, "let &so = s:so_save | let &siso = s:siso_save")
|
||||||
== FAIL)
|
== FAIL)
|
||||||
|
@@ -940,7 +940,7 @@ term_write_session(FILE *fd, win_T *wp, hashtab_T *terminal_bufs)
|
|||||||
const int bufnr = wp->w_buffer->b_fnum;
|
const int bufnr = wp->w_buffer->b_fnum;
|
||||||
term_T *term = wp->w_buffer->b_term;
|
term_T *term = wp->w_buffer->b_term;
|
||||||
|
|
||||||
if (wp->w_buffer->b_nwindows > 1)
|
if (terminal_bufs != NULL && wp->w_buffer->b_nwindows > 1)
|
||||||
{
|
{
|
||||||
// There are multiple views into this terminal buffer. We don't want to
|
// There are multiple views into this terminal buffer. We don't want to
|
||||||
// create the terminal multiple times. If it's the first time, create,
|
// create the terminal multiple times. If it's the first time, create,
|
||||||
@@ -978,7 +978,7 @@ term_write_session(FILE *fd, win_T *wp, hashtab_T *terminal_bufs)
|
|||||||
if (fprintf(fd, "let s:term_buf_%d = bufnr()", bufnr) < 0)
|
if (fprintf(fd, "let s:term_buf_%d = bufnr()", bufnr) < 0)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
if (wp->w_buffer->b_nwindows > 1)
|
if (terminal_bufs != NULL && wp->w_buffer->b_nwindows > 1)
|
||||||
{
|
{
|
||||||
char *hash_key = alloc(NUMBUFLEN);
|
char *hash_key = alloc(NUMBUFLEN);
|
||||||
|
|
||||||
|
@@ -351,9 +351,8 @@ func Test_mksession_blank_windows()
|
|||||||
call delete('Xtest_mks.out')
|
call delete('Xtest_mks.out')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
if has('terminal')
|
|
||||||
|
|
||||||
func Test_mksession_terminal_shell()
|
func Test_mksession_terminal_shell()
|
||||||
|
CheckFeature terminal
|
||||||
CheckFeature quickfix
|
CheckFeature quickfix
|
||||||
|
|
||||||
terminal
|
terminal
|
||||||
@@ -374,6 +373,8 @@ func Test_mksession_terminal_shell()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_mksession_terminal_no_restore_cmdarg()
|
func Test_mksession_terminal_no_restore_cmdarg()
|
||||||
|
CheckFeature terminal
|
||||||
|
|
||||||
terminal ++norestore
|
terminal ++norestore
|
||||||
mksession! Xtest_mks.out
|
mksession! Xtest_mks.out
|
||||||
let lines = readfile('Xtest_mks.out')
|
let lines = readfile('Xtest_mks.out')
|
||||||
@@ -389,6 +390,8 @@ func Test_mksession_terminal_no_restore_cmdarg()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_mksession_terminal_no_restore_funcarg()
|
func Test_mksession_terminal_no_restore_funcarg()
|
||||||
|
CheckFeature terminal
|
||||||
|
|
||||||
call term_start(&shell, {'norestore': 1})
|
call term_start(&shell, {'norestore': 1})
|
||||||
mksession! Xtest_mks.out
|
mksession! Xtest_mks.out
|
||||||
let lines = readfile('Xtest_mks.out')
|
let lines = readfile('Xtest_mks.out')
|
||||||
@@ -404,6 +407,8 @@ func Test_mksession_terminal_no_restore_funcarg()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_mksession_terminal_no_restore_func()
|
func Test_mksession_terminal_no_restore_func()
|
||||||
|
CheckFeature terminal
|
||||||
|
|
||||||
terminal
|
terminal
|
||||||
call term_setrestore(bufnr('%'), 'NONE')
|
call term_setrestore(bufnr('%'), 'NONE')
|
||||||
mksession! Xtest_mks.out
|
mksession! Xtest_mks.out
|
||||||
@@ -420,6 +425,8 @@ func Test_mksession_terminal_no_restore_func()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_mksession_terminal_no_ssop()
|
func Test_mksession_terminal_no_ssop()
|
||||||
|
CheckFeature terminal
|
||||||
|
|
||||||
terminal
|
terminal
|
||||||
set sessionoptions-=terminal
|
set sessionoptions-=terminal
|
||||||
mksession! Xtest_mks.out
|
mksession! Xtest_mks.out
|
||||||
@@ -437,6 +444,7 @@ func Test_mksession_terminal_no_ssop()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_mksession_terminal_restore_other()
|
func Test_mksession_terminal_restore_other()
|
||||||
|
CheckFeature terminal
|
||||||
CheckFeature quickfix
|
CheckFeature quickfix
|
||||||
|
|
||||||
terminal
|
terminal
|
||||||
@@ -456,6 +464,8 @@ func Test_mksession_terminal_restore_other()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_mksession_terminal_shared_windows()
|
func Test_mksession_terminal_shared_windows()
|
||||||
|
CheckFeature terminal
|
||||||
|
|
||||||
terminal
|
terminal
|
||||||
let term_buf = bufnr()
|
let term_buf = bufnr()
|
||||||
new
|
new
|
||||||
@@ -481,7 +491,18 @@ func Test_mksession_terminal_shared_windows()
|
|||||||
call delete('Xtest_mks.out')
|
call delete('Xtest_mks.out')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
endif " has('terminal')
|
func Test_mkview_terminal_windows()
|
||||||
|
CheckFeature terminal
|
||||||
|
|
||||||
|
" create two window on the same terminal to check this is handled OK
|
||||||
|
terminal
|
||||||
|
let term_buf = bufnr()
|
||||||
|
exe 'sbuf ' .. term_buf
|
||||||
|
mkview! Xtestview
|
||||||
|
|
||||||
|
call StopShellInTerminal(term_buf)
|
||||||
|
call delete('Xtestview')
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Test :mkview with a file argument.
|
" Test :mkview with a file argument.
|
||||||
func Test_mkview_file()
|
func Test_mkview_file()
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1664,
|
||||||
/**/
|
/**/
|
||||||
1663,
|
1663,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user