Karsten Hopp 510c26
To: vim_dev@googlegroups.com
Karsten Hopp 510c26
Subject: Patch 7.4.871
Karsten Hopp 510c26
Fcc: outbox
Karsten Hopp 510c26
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 510c26
Mime-Version: 1.0
Karsten Hopp 510c26
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 510c26
Content-Transfer-Encoding: 8bit
Karsten Hopp 510c26
------------
Karsten Hopp 510c26
Karsten Hopp 510c26
Patch 7.4.871
Karsten Hopp 510c26
Problem:    Vim leaks memory, when 'wildignore' filters out all matches.
Karsten Hopp 510c26
Solution:   Free the files array when it becomes empty.
Karsten Hopp 510c26
Files:      src/misc1.c
Karsten Hopp 510c26
Karsten Hopp 510c26
Karsten Hopp 510c26
*** ../vim-7.4.870/src/misc1.c	2015-09-01 16:25:28.357392851 +0200
Karsten Hopp 510c26
--- src/misc1.c	2015-09-15 19:00:07.569914562 +0200
Karsten Hopp 510c26
***************
Karsten Hopp 510c26
*** 9697,9710 ****
Karsten Hopp 510c26
  /*
Karsten Hopp 510c26
   * Expand wildcards.  Calls gen_expand_wildcards() and removes files matching
Karsten Hopp 510c26
   * 'wildignore'.
Karsten Hopp 510c26
!  * Returns OK or FAIL.  When FAIL then "num_file" won't be set.
Karsten Hopp 510c26
   */
Karsten Hopp 510c26
      int
Karsten Hopp 510c26
! expand_wildcards(num_pat, pat, num_file, file, flags)
Karsten Hopp 510c26
      int		   num_pat;	/* number of input patterns */
Karsten Hopp 510c26
      char_u	 **pat;		/* array of input patterns */
Karsten Hopp 510c26
!     int		  *num_file;	/* resulting number of files */
Karsten Hopp 510c26
!     char_u	***file;	/* array of resulting files */
Karsten Hopp 510c26
      int		   flags;	/* EW_DIR, etc. */
Karsten Hopp 510c26
  {
Karsten Hopp 510c26
      int		retval;
Karsten Hopp 510c26
--- 9697,9710 ----
Karsten Hopp 510c26
  /*
Karsten Hopp 510c26
   * Expand wildcards.  Calls gen_expand_wildcards() and removes files matching
Karsten Hopp 510c26
   * 'wildignore'.
Karsten Hopp 510c26
!  * Returns OK or FAIL.  When FAIL then "num_files" won't be set.
Karsten Hopp 510c26
   */
Karsten Hopp 510c26
      int
Karsten Hopp 510c26
! expand_wildcards(num_pat, pat, num_files, files, flags)
Karsten Hopp 510c26
      int		   num_pat;	/* number of input patterns */
Karsten Hopp 510c26
      char_u	 **pat;		/* array of input patterns */
Karsten Hopp 510c26
!     int		  *num_files;	/* resulting number of files */
Karsten Hopp 510c26
!     char_u	***files;	/* array of resulting files */
Karsten Hopp 510c26
      int		   flags;	/* EW_DIR, etc. */
Karsten Hopp 510c26
  {
Karsten Hopp 510c26
      int		retval;
Karsten Hopp 510c26
***************
Karsten Hopp 510c26
*** 9712,9718 ****
Karsten Hopp 510c26
      char_u	*p;
Karsten Hopp 510c26
      int		non_suf_match;	/* number without matching suffix */
Karsten Hopp 510c26
  
Karsten Hopp 510c26
!     retval = gen_expand_wildcards(num_pat, pat, num_file, file, flags);
Karsten Hopp 510c26
  
Karsten Hopp 510c26
      /* When keeping all matches, return here */
Karsten Hopp 510c26
      if ((flags & EW_KEEPALL) || retval == FAIL)
Karsten Hopp 510c26
--- 9712,9718 ----
Karsten Hopp 510c26
      char_u	*p;
Karsten Hopp 510c26
      int		non_suf_match;	/* number without matching suffix */
Karsten Hopp 510c26
  
Karsten Hopp 510c26
!     retval = gen_expand_wildcards(num_pat, pat, num_files, files, flags);
Karsten Hopp 510c26
  
Karsten Hopp 510c26
      /* When keeping all matches, return here */
Karsten Hopp 510c26
      if ((flags & EW_KEEPALL) || retval == FAIL)
Karsten Hopp 510c26
***************
Karsten Hopp 510c26
*** 9726,9772 ****
Karsten Hopp 510c26
      {
Karsten Hopp 510c26
  	char_u	*ffname;
Karsten Hopp 510c26
  
Karsten Hopp 510c26
! 	/* check all files in (*file)[] */
Karsten Hopp 510c26
! 	for (i = 0; i < *num_file; ++i)
Karsten Hopp 510c26
  	{
Karsten Hopp 510c26
! 	    ffname = FullName_save((*file)[i], FALSE);
Karsten Hopp 510c26
  	    if (ffname == NULL)		/* out of memory */
Karsten Hopp 510c26
  		break;
Karsten Hopp 510c26
  # ifdef VMS
Karsten Hopp 510c26
  	    vms_remove_version(ffname);
Karsten Hopp 510c26
  # endif
Karsten Hopp 510c26
! 	    if (match_file_list(p_wig, (*file)[i], ffname))
Karsten Hopp 510c26
  	    {
Karsten Hopp 510c26
! 		/* remove this matching file from the list */
Karsten Hopp 510c26
! 		vim_free((*file)[i]);
Karsten Hopp 510c26
! 		for (j = i; j + 1 < *num_file; ++j)
Karsten Hopp 510c26
! 		    (*file)[j] = (*file)[j + 1];
Karsten Hopp 510c26
! 		--*num_file;
Karsten Hopp 510c26
  		--i;
Karsten Hopp 510c26
  	    }
Karsten Hopp 510c26
  	    vim_free(ffname);
Karsten Hopp 510c26
  	}
Karsten Hopp 510c26
      }
Karsten Hopp 510c26
  #endif
Karsten Hopp 510c26
  
Karsten Hopp 510c26
      /*
Karsten Hopp 510c26
       * Move the names where 'suffixes' match to the end.
Karsten Hopp 510c26
       */
Karsten Hopp 510c26
!     if (*num_file > 1)
Karsten Hopp 510c26
      {
Karsten Hopp 510c26
  	non_suf_match = 0;
Karsten Hopp 510c26
! 	for (i = 0; i < *num_file; ++i)
Karsten Hopp 510c26
  	{
Karsten Hopp 510c26
! 	    if (!match_suffix((*file)[i]))
Karsten Hopp 510c26
  	    {
Karsten Hopp 510c26
  		/*
Karsten Hopp 510c26
  		 * Move the name without matching suffix to the front
Karsten Hopp 510c26
  		 * of the list.
Karsten Hopp 510c26
  		 */
Karsten Hopp 510c26
! 		p = (*file)[i];
Karsten Hopp 510c26
  		for (j = i; j > non_suf_match; --j)
Karsten Hopp 510c26
! 		    (*file)[j] = (*file)[j - 1];
Karsten Hopp 510c26
! 		(*file)[non_suf_match++] = p;
Karsten Hopp 510c26
  	    }
Karsten Hopp 510c26
  	}
Karsten Hopp 510c26
      }
Karsten Hopp 510c26
--- 9726,9780 ----
Karsten Hopp 510c26
      {
Karsten Hopp 510c26
  	char_u	*ffname;
Karsten Hopp 510c26
  
Karsten Hopp 510c26
! 	/* check all files in (*files)[] */
Karsten Hopp 510c26
! 	for (i = 0; i < *num_files; ++i)
Karsten Hopp 510c26
  	{
Karsten Hopp 510c26
! 	    ffname = FullName_save((*files)[i], FALSE);
Karsten Hopp 510c26
  	    if (ffname == NULL)		/* out of memory */
Karsten Hopp 510c26
  		break;
Karsten Hopp 510c26
  # ifdef VMS
Karsten Hopp 510c26
  	    vms_remove_version(ffname);
Karsten Hopp 510c26
  # endif
Karsten Hopp 510c26
! 	    if (match_file_list(p_wig, (*files)[i], ffname))
Karsten Hopp 510c26
  	    {
Karsten Hopp 510c26
! 		/* remove this matching files from the list */
Karsten Hopp 510c26
! 		vim_free((*files)[i]);
Karsten Hopp 510c26
! 		for (j = i; j + 1 < *num_files; ++j)
Karsten Hopp 510c26
! 		    (*files)[j] = (*files)[j + 1];
Karsten Hopp 510c26
! 		--*num_files;
Karsten Hopp 510c26
  		--i;
Karsten Hopp 510c26
  	    }
Karsten Hopp 510c26
  	    vim_free(ffname);
Karsten Hopp 510c26
  	}
Karsten Hopp 510c26
+ 
Karsten Hopp 510c26
+ 	/* If the number of matches is now zero, we fail. */
Karsten Hopp 510c26
+ 	if (*num_files == 0)
Karsten Hopp 510c26
+ 	{
Karsten Hopp 510c26
+ 	    vim_free(*files);
Karsten Hopp 510c26
+ 	    *files = NULL;
Karsten Hopp 510c26
+ 	    return FAIL;
Karsten Hopp 510c26
+ 	}
Karsten Hopp 510c26
      }
Karsten Hopp 510c26
  #endif
Karsten Hopp 510c26
  
Karsten Hopp 510c26
      /*
Karsten Hopp 510c26
       * Move the names where 'suffixes' match to the end.
Karsten Hopp 510c26
       */
Karsten Hopp 510c26
!     if (*num_files > 1)
Karsten Hopp 510c26
      {
Karsten Hopp 510c26
  	non_suf_match = 0;
Karsten Hopp 510c26
! 	for (i = 0; i < *num_files; ++i)
Karsten Hopp 510c26
  	{
Karsten Hopp 510c26
! 	    if (!match_suffix((*files)[i]))
Karsten Hopp 510c26
  	    {
Karsten Hopp 510c26
  		/*
Karsten Hopp 510c26
  		 * Move the name without matching suffix to the front
Karsten Hopp 510c26
  		 * of the list.
Karsten Hopp 510c26
  		 */
Karsten Hopp 510c26
! 		p = (*files)[i];
Karsten Hopp 510c26
  		for (j = i; j > non_suf_match; --j)
Karsten Hopp 510c26
! 		    (*files)[j] = (*files)[j - 1];
Karsten Hopp 510c26
! 		(*files)[non_suf_match++] = p;
Karsten Hopp 510c26
  	    }
Karsten Hopp 510c26
  	}
Karsten Hopp 510c26
      }
Karsten Hopp 510c26
*** ../vim-7.4.870/src/version.c	2015-09-15 18:29:35.488932799 +0200
Karsten Hopp 510c26
--- src/version.c	2015-09-15 18:58:45.310768934 +0200
Karsten Hopp 510c26
***************
Karsten Hopp 510c26
*** 743,744 ****
Karsten Hopp 510c26
--- 743,746 ----
Karsten Hopp 510c26
  {   /* Add new patch number below this line */
Karsten Hopp 510c26
+ /**/
Karsten Hopp 510c26
+     871,
Karsten Hopp 510c26
  /**/
Karsten Hopp 510c26
Karsten Hopp 510c26
-- 
Karsten Hopp 510c26
Team-building exercises come in many forms but they all trace their roots back
Karsten Hopp 510c26
to the prison system.  In your typical team-building exercise the employees
Karsten Hopp 510c26
are subjected to a variety of unpleasant situations until they become either a
Karsten Hopp 510c26
cohesive team or a ring of car jackers.
Karsten Hopp 510c26
				(Scott Adams - The Dilbert principle)
Karsten Hopp 510c26
Karsten Hopp 510c26
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 510c26
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 510c26
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 510c26
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///