ex_terminal(): fix double-free

Closes #4554
This commit is contained in:
Justin M. Keyes
2016-05-15 16:56:29 -04:00
parent 3320b99816
commit 36fb600a9e
2 changed files with 9 additions and 5 deletions

View File

@@ -9497,12 +9497,14 @@ static void ex_folddo(exarg_T *eap)
static void ex_terminal(exarg_T *eap)
{
// We will call termopen() with ['shell'] if not given a {cmd}.
char *name = (char *)p_sh;
char *name = (char *)p_sh; // Default to 'shell' if {cmd} is not given.
bool mustfree = false;
char *lquote = "['";
char *rquote = "']";
if (*eap->arg != NUL) {
name = (char *)vim_strsave_escaped(eap->arg, (char_u *)"\"\\");
mustfree = true;
lquote = rquote = "\"";
}
@@ -9512,7 +9514,7 @@ static void ex_terminal(exarg_T *eap)
eap->forceit==TRUE ? "!" : "", lquote, name, rquote);
do_cmdline_cmd(ex_cmd);
if (name != (char *)p_sh) {
if (mustfree) {
xfree(name);
}
}