]> granicus.if.org Git - vim/commitdiff
patch 7.4.871 v7.4.871
authorBram Moolenaar <Bram@vim.org>
Tue, 15 Sep 2015 17:05:59 +0000 (19:05 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 15 Sep 2015 17:05:59 +0000 (19:05 +0200)
Problem:    Vim leaks memory, when 'wildignore' filters out all matches.
Solution:   Free the files array when it becomes empty.

src/misc1.c
src/version.c

index 8b5ea647e8e99cb29267a665cb467f664342cd49..7eb3dce8b90f20a9e957c3ec0120169df220a657 100644 (file)
@@ -9697,14 +9697,14 @@ expand_wildcards_eval(pat, num_file, file, flags)
 /*
  * Expand wildcards.  Calls gen_expand_wildcards() and removes files matching
  * 'wildignore'.
- * Returns OK or FAIL.  When FAIL then "num_file" won't be set.
+ * Returns OK or FAIL.  When FAIL then "num_files" won't be set.
  */
     int
-expand_wildcards(num_pat, pat, num_file, file, flags)
+expand_wildcards(num_pat, pat, num_files, files, flags)
     int                   num_pat;     /* number of input patterns */
     char_u      **pat;         /* array of input patterns */
-    int                  *num_file   /* resulting number of files */
-    char_u     ***file       /* array of resulting files */
+    int                  *num_files;   /* resulting number of files */
+    char_u     ***files;       /* array of resulting files */
     int                   flags;       /* EW_DIR, etc. */
 {
     int                retval;
@@ -9712,7 +9712,7 @@ expand_wildcards(num_pat, pat, num_file, file, flags)
     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)
@@ -9726,47 +9726,55 @@ expand_wildcards(num_pat, pat, num_file, file, flags)
     {
        char_u  *ffname;
 
-       /* check all files in (*file)[] */
-       for (i = 0; i < *num_file; ++i)
+       /* check all files in (*files)[] */
+       for (i = 0; i < *num_files; ++i)
        {
-           ffname = FullName_save((*file)[i], FALSE);
+           ffname = FullName_save((*files)[i], FALSE);
            if (ffname == NULL)         /* out of memory */
                break;
 # ifdef VMS
            vms_remove_version(ffname);
 # endif
-           if (match_file_list(p_wig, (*file)[i], ffname))
+           if (match_file_list(p_wig, (*files)[i], ffname))
            {
-               /* remove this matching file from the list */
-               vim_free((*file)[i]);
-               for (j = i; j + 1 < *num_file; ++j)
-                   (*file)[j] = (*file)[j + 1];
-               --*num_file;
+               /* remove this matching files from the list */
+               vim_free((*files)[i]);
+               for (j = i; j + 1 < *num_files; ++j)
+                   (*files)[j] = (*files)[j + 1];
+               --*num_files;
                --i;
            }
            vim_free(ffname);
        }
+
+       /* If the number of matches is now zero, we fail. */
+       if (*num_files == 0)
+       {
+           vim_free(*files);
+           *files = NULL;
+           return FAIL;
+       }
     }
 #endif
 
     /*
      * 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)
+       for (i = 0; i < *num_files; ++i)
        {
-           if (!match_suffix((*file)[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;
            }
        }
     }
index 0cb1fc62b59a78989c90f2d5a76e129d7d5c93b3..20107c50156c1144e1f9fb99b822d2e9967f8d08 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    871,
 /**/
     870,
 /**/