Skip to content

Commit 4fa1019

Browse files
committed
patch 8.0.0942: using freed memory with ":terminal"
Problem: Using freed memory with ":terminal" if an autocommand changes 'shell' when splitting the window. (Marius Gedminas) Solution: Make a copy of 'shell'. (closes #1974)
1 parent 05fbfdc commit 4fa1019

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/terminal.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit)
392392
setup_job_options(opt, term->tl_rows, term->tl_cols);
393393

394394
/* System dependent: setup the vterm and start the job in it. */
395-
if (term_and_job_init(term, term->tl_rows, term->tl_cols, argvar, opt) == OK)
395+
if (term_and_job_init(term, term->tl_rows, term->tl_cols, argvar, opt)
396+
== OK)
396397
{
397398
/* Get and remember the size we ended up with. Update the pty. */
398399
vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols);
@@ -434,6 +435,7 @@ ex_terminal(exarg_T *eap)
434435
typval_T argvar;
435436
jobopt_T opt;
436437
char_u *cmd;
438+
char_u *tofree = NULL;
437439

438440
init_job_options(&opt);
439441

@@ -462,7 +464,8 @@ ex_terminal(exarg_T *eap)
462464
cmd = skipwhite(p);
463465
}
464466
if (cmd == NULL || *cmd == NUL)
465-
cmd = p_sh;
467+
/* Make a copy, an autocommand may set 'shell'. */
468+
tofree = cmd = vim_strsave(p_sh);
466469

467470
if (eap->addr_count == 2)
468471
{
@@ -480,6 +483,7 @@ ex_terminal(exarg_T *eap)
480483
argvar.v_type = VAR_STRING;
481484
argvar.vval.v_string = cmd;
482485
term_start(&argvar, &opt, eap->forceit);
486+
vim_free(tofree);
483487
}
484488

485489
/*

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
942,
772774
/**/
773775
941,
774776
/**/

0 commit comments

Comments
 (0)