Skip to content

Commit

Permalink
patch 8.0.0942: using freed memory with ":terminal"
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
brammool committed Aug 14, 2017
1 parent 05fbfdc commit 4fa1019
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit)
setup_job_options(opt, term->tl_rows, term->tl_cols);

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

init_job_options(&opt);

Expand Down Expand Up @@ -462,7 +464,8 @@ ex_terminal(exarg_T *eap)
cmd = skipwhite(p);
}
if (cmd == NULL || *cmd == NUL)
cmd = p_sh;
/* Make a copy, an autocommand may set 'shell'. */
tofree = cmd = vim_strsave(p_sh);

if (eap->addr_count == 2)
{
Expand All @@ -480,6 +483,7 @@ ex_terminal(exarg_T *eap)
argvar.v_type = VAR_STRING;
argvar.vval.v_string = cmd;
term_start(&argvar, &opt, eap->forceit);
vim_free(tofree);
}

/*
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
942,
/**/
941,
/**/
Expand Down

0 comments on commit 4fa1019

Please sign in to comment.