aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2015-09-10 20:52:25 -0400
committerJustin M. Keyes <justinkz@gmail.com>2015-09-10 20:52:25 -0400
commitb762e809e40271ad8cad13995a1f0cbdabc10f33 (patch)
treef894abf058898e7aa739f6354abb2f51d4da3c00
parent7031364c7693d2a73b49c421aeee1c82bd0346b6 (diff)
parent367fc419434101d7f4bb1b40534bad94f0c027de (diff)
downloadrneovim-b762e809e40271ad8cad13995a1f0cbdabc10f33.tar.gz
rneovim-b762e809e40271ad8cad13995a1f0cbdabc10f33.tar.bz2
rneovim-b762e809e40271ad8cad13995a1f0cbdabc10f33.zip
Merge pull request #3322 from oni-link/fix.memory.leak.2
path.c: Fix memory leak in expand_wildcards().
-rw-r--r--src/nvim/ex_getln.c9
-rw-r--r--src/nvim/path.c17
2 files changed, 18 insertions, 8 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 03116d454f..a9d371d0eb 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -4112,10 +4112,11 @@ void globpath(char_u *path, char_u *file, garray_T *ga, int expand_options)
STRCAT(buf, file); // NOLINT
char_u **p;
- int num_p;
- if (ExpandFromContext(&xpc, buf, &num_p, &p,
- WILD_SILENT|expand_options) != FAIL && num_p > 0) {
- ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options);
+ int num_p = 0;
+ (void)ExpandFromContext(&xpc, buf, &num_p, &p,
+ WILD_SILENT | expand_options);
+ if (num_p > 0) {
+ ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT | expand_options);
// Concatenate new results to previous ones.
ga_grow(ga, num_p);
diff --git a/src/nvim/path.c b/src/nvim/path.c
index a3b5bb7490..1a1f15e8f3 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -1843,7 +1843,11 @@ char_u *path_shorten_fname(char_u *full_path, char_u *dir_name)
/// @param[out] file Array of resulting files.
/// @param[in] flags Flags passed to expand_wildcards().
///
-/// @return OK or FAIL.
+/// @returns OK when *file is set to allocated array of matches
+/// and *num_file(can be zero) to the number of matches.
+/// If FAIL is returned, *num_file and *file are either
+/// unchanged or *num_file is set to 0 and *file is set
+/// to NULL or points to "".
int expand_wildcards_eval(char_u **pat, int *num_file, char_u ***file,
int flags)
{
@@ -1882,9 +1886,8 @@ int expand_wildcards_eval(char_u **pat, int *num_file, char_u ***file,
/// @param[out] file is pointer to array of pointers to matched file names.
/// @param flags is a combination of EW_* flags.
///
-/// @returns OK when some files were found. *num_file is set to the
-/// number of matches, *file to the allocated array of
-/// matches.
+/// @returns OK when *file is set to allocated array of matches
+/// and *num_file (can be zero) to the number of matches.
/// If FAIL is returned, *num_file and *file are either
/// unchanged or *num_file is set to 0 and *file is set to
/// NULL or points to "".
@@ -1944,6 +1947,12 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file,
}
}
+ // Free empty array of matches
+ if (*num_file == 0) {
+ xfree(*file);
+ *file = NULL;
+ }
+
return retval;
}