Patch 8.2.1664

6 views
Skip to first unread message

Bram Moolenaar

unread,
Sep 11, 2020, 4:11:13 PM9/11/20
to vim...@googlegroups.com

Patch 8.2.1664
Problem: Memory leak when using :mkview with a terminal buffer.
Solution: Don't use a hastab for :mkview. (Rob Pilling, closes #6935)
Files: src/session.c, src/terminal.c, src/testdir/test_mksession.vim


*** ../vim-8.2.1663/src/session.c 2020-09-11 20:36:32.462574370 +0200
--- src/session.c 2020-09-11 22:07:11.270214850 +0200
***************
*** 303,316 ****
put_view(
FILE *fd,
win_T *wp,
! int add_edit, // add ":edit" command to view
! unsigned *flagp, // vop_flags or ssop_flags
! int current_arg_idx // current argument index of the window, use
! // -1 if unknown
! #ifdef FEAT_TERMINAL
! , hashtab_T *terminal_bufs
! #endif
! )
{
win_T *save_curwin;
int f;
--- 303,314 ----
put_view(
FILE *fd,
win_T *wp,
! int add_edit, // add ":edit" command to view
! unsigned *flagp, // vop_flags or ssop_flags
! int current_arg_idx, // current argument index of the window,
! // use -1 if unknown
! hashtab_T *terminal_bufs UNUSED) // already encountered terminal buffers,
! // can be NULL
{
win_T *save_curwin;
int f;
***************
*** 825,833 ****
{
if (!ses_do_win(wp))
continue;
! if (put_view(fd, wp, wp != edited_win, &ssop_flags, cur_arg_idx
#ifdef FEAT_TERMINAL
! , &terminal_bufs
#endif
) == FAIL)
goto fail;
--- 823,833 ----
{
if (!ses_do_win(wp))
continue;
! if (put_view(fd, wp, wp != edited_win, &ssop_flags, cur_arg_idx,
#ifdef FEAT_TERMINAL
! &terminal_bufs
! #else
! NULL
#endif
) == FAIL)
goto fail;
***************
*** 1102,1112 ****
char_u *viewFile = NULL;
unsigned *flagp;
#endif
- #ifdef FEAT_TERMINAL
- hashtab_T terminal_bufs;
-
- hash_init(&terminal_bufs);
- #endif

if (eap->cmdidx == CMD_mksession || eap->cmdidx == CMD_mkview)
{
--- 1102,1107 ----
***************
*** 1263,1273 ****
}
else
{
! failed |= (put_view(fd, curwin, !using_vdir, flagp, -1
! #ifdef FEAT_TERMINAL
! , &terminal_bufs
! #endif
! ) == FAIL);
}
if (put_line(fd, "let &so = s:so_save | let &siso = s:siso_save")
== FAIL)
--- 1258,1265 ----
}
else
{
! failed |= (put_view(fd, curwin, !using_vdir, flagp, -1, NULL)
! == FAIL);
}
if (put_line(fd, "let &so = s:so_save | let &siso = s:siso_save")
== FAIL)
*** ../vim-8.2.1663/src/terminal.c 2020-09-11 20:36:32.462574370 +0200
--- src/terminal.c 2020-09-11 22:04:17.474783303 +0200
***************
*** 940,946 ****
const int bufnr = wp->w_buffer->b_fnum;
term_T *term = wp->w_buffer->b_term;

! if (wp->w_buffer->b_nwindows > 1)
{
// 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,
--- 940,946 ----
const int bufnr = wp->w_buffer->b_fnum;
term_T *term = wp->w_buffer->b_term;

! if (terminal_bufs != NULL && wp->w_buffer->b_nwindows > 1)
{
// 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,
***************
*** 978,984 ****
if (fprintf(fd, "let s:term_buf_%d = bufnr()", bufnr) < 0)
return FAIL;

! if (wp->w_buffer->b_nwindows > 1)
{
char *hash_key = alloc(NUMBUFLEN);

--- 978,984 ----
if (fprintf(fd, "let s:term_buf_%d = bufnr()", bufnr) < 0)
return FAIL;

! if (terminal_bufs != NULL && wp->w_buffer->b_nwindows > 1)
{
char *hash_key = alloc(NUMBUFLEN);

*** ../vim-8.2.1663/src/testdir/test_mksession.vim 2020-09-11 20:36:32.466574355 +0200
--- src/testdir/test_mksession.vim 2020-09-11 21:59:05.867703897 +0200
***************
*** 351,359 ****
call delete('Xtest_mks.out')
endfunc

- if has('terminal')
-
func Test_mksession_terminal_shell()
CheckFeature quickfix

terminal
--- 351,358 ----
call delete('Xtest_mks.out')
endfunc

func Test_mksession_terminal_shell()
+ CheckFeature terminal
CheckFeature quickfix

terminal
***************
*** 374,379 ****
--- 373,380 ----
endfunc

func Test_mksession_terminal_no_restore_cmdarg()
+ CheckFeature terminal
+
terminal ++norestore
mksession! Xtest_mks.out
let lines = readfile('Xtest_mks.out')
***************
*** 389,394 ****
--- 390,397 ----
endfunc

func Test_mksession_terminal_no_restore_funcarg()
+ CheckFeature terminal
+
call term_start(&shell, {'norestore': 1})
mksession! Xtest_mks.out
let lines = readfile('Xtest_mks.out')
***************
*** 404,409 ****
--- 407,414 ----
endfunc

func Test_mksession_terminal_no_restore_func()
+ CheckFeature terminal
+
terminal
call term_setrestore(bufnr('%'), 'NONE')
mksession! Xtest_mks.out
***************
*** 420,425 ****
--- 425,432 ----
endfunc

func Test_mksession_terminal_no_ssop()
+ CheckFeature terminal
+
terminal
set sessionoptions-=terminal
mksession! Xtest_mks.out
***************
*** 437,442 ****
--- 444,450 ----
endfunc

func Test_mksession_terminal_restore_other()
+ CheckFeature terminal
CheckFeature quickfix

terminal
***************
*** 456,461 ****
--- 464,471 ----
endfunc

func Test_mksession_terminal_shared_windows()
+ CheckFeature terminal
+
terminal
let term_buf = bufnr()
new
***************
*** 481,487 ****
call delete('Xtest_mks.out')
endfunc

! endif " has('terminal')

" Test :mkview with a file argument.
func Test_mkview_file()
--- 491,508 ----
call delete('Xtest_mks.out')
endfunc

! 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.
func Test_mkview_file()
*** ../vim-8.2.1663/src/version.c 2020-09-11 20:51:22.835620641 +0200
--- src/version.c 2020-09-11 22:04:07.830811948 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 1664,
/**/

--
Q: What kind of stuff do you do?
A: I collect hobbies.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages