Fix xfree of static value in expand_shellcmd()

The refactoring of vim_getenv() to remove the mustfree arg
included reworking calling functions.  expand_shellcmd was
also using that to track its usage of the variable within
the function, resulting in #2487. This change addresses
that scenario and cleans up some of the function for style.
This commit is contained in:
Mark Bainter 2015-04-23 15:35:13 +00:00
parent 04e098fc3c
commit b68ce1460d

View File

@ -3841,6 +3841,7 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
flags |= EW_FILE | EW_EXEC; flags |= EW_FILE | EW_EXEC;
bool mustfree = false; // Track memory allocation for *path.
/* For an absolute name we don't use $PATH. */ /* For an absolute name we don't use $PATH. */
if (path_is_absolute_path(pat)) if (path_is_absolute_path(pat))
path = (char_u *)" "; path = (char_u *)" ";
@ -3849,8 +3850,11 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
path = (char_u *)"."; path = (char_u *)".";
else { else {
path = (char_u *)vim_getenv("PATH"); path = (char_u *)vim_getenv("PATH");
if (path == NULL) if (path == NULL) {
path = (char_u *)""; path = (char_u *)"";
} else {
mustfree = true;
}
} }
/* /*
@ -3899,7 +3903,9 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
xfree(buf); xfree(buf);
xfree(pat); xfree(pat);
xfree(path); if (mustfree) {
xfree(path);
}
} }
/* /*