From c107d4a2d640f00380a97f59499d65da7abf9118 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Fri, 22 Apr 2016 20:01:36 +0200 Subject: The trivial part of 7.4.871 --- src/nvim/path.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/nvim/path.c b/src/nvim/path.c index d3df9bc059..1fe0a1040c 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1926,7 +1926,7 @@ int expand_wildcards_eval(char_u **pat, int *num_file, char_u ***file, /// 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(int num_pat, char_u **pat, int *num_file, char_u ***file, +int expand_wildcards(int num_pat, char_u **pat, int *num_files, char_u ***files, int flags) { int retval; @@ -1934,7 +1934,7 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file, char_u *p; int non_suf_match; /* number without matching suffix */ - retval = gen_expand_wildcards(num_pat, pat, num_file, file, flags); + retval = gen_expand_wildcards(num_pat, pat, num_files, files, flags); /* When keeping all matches, return here */ if ((flags & EW_KEEPALL) || retval == FAIL) @@ -1946,17 +1946,17 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file, if (*p_wig) { char_u *ffname; - /* check all files in (*file)[] */ - for (i = 0; i < *num_file; ++i) { - ffname = (char_u *)FullName_save((char *)(*file)[i], FALSE); + /* check all filess in (*files)[] */ + for (i = 0; i < *num_files; ++i) { + ffname = (char_u *)FullName_save((char *)(*files)[i], FALSE); if (ffname == NULL) /* out of memory */ break; - if (match_file_list(p_wig, (*file)[i], ffname)) { - /* remove this matching file from the list */ - xfree((*file)[i]); - for (j = i; j + 1 < *num_file; ++j) - (*file)[j] = (*file)[j + 1]; - --*num_file; + if (match_file_list(p_wig, (*files)[i], ffname)) { + /* remove this matching files from the list */ + xfree((*files)[i]); + for (j = i; j + 1 < *num_files; ++j) + (*files)[j] = (*files)[j + 1]; + --*num_files; --i; } xfree(ffname); @@ -1966,26 +1966,26 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file, /* * Move the names where 'suffixes' match to the end. */ - if (*num_file > 1) { + if (*num_files > 1) { non_suf_match = 0; - for (i = 0; i < *num_file; ++i) { - if (!match_suffix((*file)[i])) { + for (i = 0; i < *num_files; ++i) { + if (!match_suffix((*files)[i])) { /* * Move the name without matching suffix to the front * of the list. */ - p = (*file)[i]; + p = (*files)[i]; for (j = i; j > non_suf_match; --j) - (*file)[j] = (*file)[j - 1]; - (*file)[non_suf_match++] = p; + (*files)[j] = (*files)[j - 1]; + (*files)[non_suf_match++] = p; } } } // Free empty array of matches - if (*num_file == 0) { - xfree(*file); - *file = NULL; + if (*num_files == 0) { + xfree(*files); + *files = NULL; } return retval; -- cgit From e6b8893337f843d685b26f59d1982e23871956bf Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Fri, 22 Apr 2016 19:47:41 +0200 Subject: vim-patch:7.4.871 Problem: Vim leaks memory, when 'wildignore' filters out all matches. Solution: Free the files array when it becomes empty. https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696 The only nontrivial part of 7.4.871 missing (renamings of variables are in another commit; freeing *files after 0 matches was already there, just FAIL was not returned in that case) --- src/nvim/path.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/nvim/path.c b/src/nvim/path.c index 1fe0a1040c..f2b0662eac 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1986,6 +1986,7 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_files, char_u ***files, if (*num_files == 0) { xfree(*files); *files = NULL; + return FAIL; } return retval; -- cgit From 98fb53e0ebaf1481e93427d9969086eb87faa654 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Fri, 22 Apr 2016 21:19:47 +0200 Subject: Happy little, happy little, happy little linter --- src/nvim/path.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/nvim/path.c b/src/nvim/path.c index f2b0662eac..29ff62ef77 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1946,18 +1946,20 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_files, char_u ***files, if (*p_wig) { char_u *ffname; - /* check all filess in (*files)[] */ - for (i = 0; i < *num_files; ++i) { - ffname = (char_u *)FullName_save((char *)(*files)[i], FALSE); - if (ffname == NULL) /* out of memory */ + // check all filess in (*files)[] + for (i = 0; i < *num_files; i++) { + ffname = (char_u *)FullName_save((char *)(*files)[i], false); + if (ffname == NULL) { // out of memory break; + } if (match_file_list(p_wig, (*files)[i], ffname)) { - /* remove this matching files from the list */ + // remove this matching files from the list xfree((*files)[i]); - for (j = i; j + 1 < *num_files; ++j) + for (j = i; j + 1 < *num_files; j++) { (*files)[j] = (*files)[j + 1]; - --*num_files; - --i; + } + (*num_files)--; + i--; } xfree(ffname); } @@ -1968,15 +1970,16 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_files, char_u ***files, */ if (*num_files > 1) { non_suf_match = 0; - for (i = 0; i < *num_files; ++i) { + for (i = 0; i < *num_files; i++) { if (!match_suffix((*files)[i])) { - /* - * Move the name without matching suffix to the front - * of the list. - */ + // + // Move the name without matching suffix to the front + // of the list. + // p = (*files)[i]; - for (j = i; j > non_suf_match; --j) + for (j = i; j > non_suf_match; j--) { (*files)[j] = (*files)[j - 1]; + } (*files)[non_suf_match++] = p; } } -- cgit