aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Bainter <mbainter+github@gmail.com>2015-04-23 15:35:13 +0000
committerMark Bainter <mbainter+github@gmail.com>2015-04-23 16:12:14 +0000
commitb68ce1460db13a8a443ec3c3da5c30f8f592e157 (patch)
treebd49e9472072bc7ca73c03c72eb528d18c93b0b3
parent04e098fc3c485eaa6d323e9121e9c81215d94a87 (diff)
downloadrneovim-b68ce1460db13a8a443ec3c3da5c30f8f592e157.tar.gz
rneovim-b68ce1460db13a8a443ec3c3da5c30f8f592e157.tar.bz2
rneovim-b68ce1460db13a8a443ec3c3da5c30f8f592e157.zip
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.
-rw-r--r--src/nvim/ex_getln.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 5fd5c2a345..6d5ebda256 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -3841,6 +3841,7 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
flags |= EW_FILE | EW_EXEC;
+ bool mustfree = false; // Track memory allocation for *path.
/* For an absolute name we don't use $PATH. */
if (path_is_absolute_path(pat))
path = (char_u *)" ";
@@ -3849,8 +3850,11 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
path = (char_u *)".";
else {
path = (char_u *)vim_getenv("PATH");
- if (path == NULL)
+ if (path == NULL) {
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(pat);
- xfree(path);
+ if (mustfree) {
+ xfree(path);
+ }
}
/*