44d845c
To: vim-dev@vim.org
44d845c
Subject: Patch 7.2.036 (extra)
44d845c
Fcc: outbox
44d845c
From: Bram Moolenaar <Bram@moolenaar.net>
44d845c
Mime-Version: 1.0
44d845c
Content-Type: text/plain; charset=ISO-8859-1
44d845c
Content-Transfer-Encoding: 8bit
44d845c
------------
44d845c
44d845c
Patch 7.2.036 (extra)
44d845c
Problem:    Mismatches between alloc/malloc, free/vim_free,
44d845c
	    realloc/vim_realloc.
44d845c
Solution:   Use the right function. (Dominique Pelle)
44d845c
Files:	    src/gui_riscos.c, src/gui_w48.c, src/mbyte.c, src/os_vms.c,
44d845c
	    src/os_w32exe.c, src/os_win16.c
44d845c
44d845c
44d845c
*** ../vim-7.2.035/src/gui_riscos.c	Thu May 10 19:33:26 2007
44d845c
--- src/gui_riscos.c	Wed Nov 12 11:47:54 2008
44d845c
***************
44d845c
*** 695,701 ****
44d845c
  gui_mch_set_shellsize(width, height, min_width, min_height, base_width, base_height, direction)
44d845c
      int width;		/* In OS units */
44d845c
      int height;
44d845c
!     int min_width;	/* Smallest permissable window size (ignored) */
44d845c
      int min_height;
44d845c
      int base_width;	/* Space for scroll bars, etc */
44d845c
      int base_height;
44d845c
--- 695,701 ----
44d845c
  gui_mch_set_shellsize(width, height, min_width, min_height, base_width, base_height, direction)
44d845c
      int width;		/* In OS units */
44d845c
      int height;
44d845c
!     int min_width;	/* Smallest permissible window size (ignored) */
44d845c
      int min_height;
44d845c
      int base_width;	/* Space for scroll bars, etc */
44d845c
      int base_height;
44d845c
***************
44d845c
*** 863,869 ****
44d845c
      if (strncmp(file, "ZapFont\015", 8) == 0)
44d845c
  	return file;	/* Loaded OK! */
44d845c
  
44d845c
!     free(file);
44d845c
      return NULL;	/* Not a valid font file */
44d845c
  }
44d845c
  
44d845c
--- 863,869 ----
44d845c
      if (strncmp(file, "ZapFont\015", 8) == 0)
44d845c
  	return file;	/* Loaded OK! */
44d845c
  
44d845c
!     vim_free(file);
44d845c
      return NULL;	/* Not a valid font file */
44d845c
  }
44d845c
  
44d845c
*** ../vim-7.2.035/src/gui_w48.c	Thu Jul 24 20:50:23 2008
44d845c
--- src/gui_w48.c	Wed Nov 12 11:37:41 2008
44d845c
***************
44d845c
*** 3335,3341 ****
44d845c
  
44d845c
  /*
44d845c
   * Convert the string s to the proper format for a filter string by replacing
44d845c
!  * the \t and \n delimeters with \0.
44d845c
   * Returns the converted string in allocated memory.
44d845c
   *
44d845c
   * Keep in sync with convert_filterW() above!
44d845c
--- 3335,3341 ----
44d845c
  
44d845c
  /*
44d845c
   * Convert the string s to the proper format for a filter string by replacing
44d845c
!  * the \t and \n delimiters with \0.
44d845c
   * Returns the converted string in allocated memory.
44d845c
   *
44d845c
   * Keep in sync with convert_filterW() above!
44d845c
***************
44d845c
*** 3674,3680 ****
44d845c
   * Use "prog" as the name of the program and "cmdline" as the arguments.
44d845c
   * Copy the arguments to allocated memory.
44d845c
   * Return the number of arguments (including program name).
44d845c
!  * Return pointers to the arguments in "argvp".
44d845c
   * Return pointer to buffer in "tofree".
44d845c
   * Returns zero when out of memory.
44d845c
   */
44d845c
--- 3674,3681 ----
44d845c
   * Use "prog" as the name of the program and "cmdline" as the arguments.
44d845c
   * Copy the arguments to allocated memory.
44d845c
   * Return the number of arguments (including program name).
44d845c
!  * Return pointers to the arguments in "argvp".  Memory is allocated with
44d845c
!  * malloc(), use free() instead of vim_free().
44d845c
   * Return pointer to buffer in "tofree".
44d845c
   * Returns zero when out of memory.
44d845c
   */
44d845c
***************
44d845c
*** 3692,3697 ****
44d845c
--- 3693,3700 ----
44d845c
      char	**argv = NULL;
44d845c
      int		round;
44d845c
  
44d845c
+     *tofree = NULL;
44d845c
+ 
44d845c
  #ifdef FEAT_MBYTE
44d845c
      /* Try using the Unicode version first, it takes care of conversion when
44d845c
       * 'encoding' is changed. */
44d845c
***************
44d845c
*** 3802,3816 ****
44d845c
  	    argv = (char **)malloc((argc + 1) * sizeof(char *));
44d845c
  	    if (argv == NULL )
44d845c
  	    {
44d845c
! 		vim_free(newcmdline);
44d845c
  		return 0;		   /* malloc error */
44d845c
  	    }
44d845c
  	    pnew = newcmdline;
44d845c
  	}
44d845c
      }
44d845c
  
44d845c
  done:
44d845c
- 
44d845c
      argv[argc] = NULL;		/* NULL-terminated list */
44d845c
      *argvp = argv;
44d845c
      return argc;
44d845c
--- 3805,3819 ----
44d845c
  	    argv = (char **)malloc((argc + 1) * sizeof(char *));
44d845c
  	    if (argv == NULL )
44d845c
  	    {
44d845c
! 		free(newcmdline);
44d845c
  		return 0;		   /* malloc error */
44d845c
  	    }
44d845c
  	    pnew = newcmdline;
44d845c
+ 	    *tofree = newcmdline;
44d845c
  	}
44d845c
      }
44d845c
  
44d845c
  done:
44d845c
      argv[argc] = NULL;		/* NULL-terminated list */
44d845c
      *argvp = argv;
44d845c
      return argc;
44d845c
*** ../vim-7.2.035/src/os_vms.c	Wed Aug  6 18:38:52 2008
44d845c
--- src/os_vms.c	Wed Nov 12 11:42:12 2008
44d845c
***************
44d845c
*** 228,234 ****
44d845c
      else if ((sbuf = getenv((char *)lognam)))
44d845c
      {
44d845c
  	lengte = strlen(sbuf) + 1;
44d845c
! 	cp = (char_u *)malloc((size_t)lengte);
44d845c
  	if (cp)
44d845c
  	    strcpy((char *)cp, sbuf);
44d845c
  	return cp;
44d845c
--- 228,234 ----
44d845c
      else if ((sbuf = getenv((char *)lognam)))
44d845c
      {
44d845c
  	lengte = strlen(sbuf) + 1;
44d845c
! 	cp = (char_u *)alloc((size_t)lengte);
44d845c
  	if (cp)
44d845c
  	    strcpy((char *)cp, sbuf);
44d845c
  	return cp;
44d845c
***************
44d845c
*** 381,387 ****
44d845c
      if (--vms_match_free == 0) {
44d845c
  	/* add more space to store matches */
44d845c
  	vms_match_alloced += EXPL_ALLOC_INC;
44d845c
! 	vms_fmatch = (char_u **)realloc(vms_fmatch,
44d845c
  		sizeof(char **) * vms_match_alloced);
44d845c
  	if (!vms_fmatch)
44d845c
  	    return 0;
44d845c
--- 381,387 ----
44d845c
      if (--vms_match_free == 0) {
44d845c
  	/* add more space to store matches */
44d845c
  	vms_match_alloced += EXPL_ALLOC_INC;
44d845c
! 	vms_fmatch = (char_u **)vim_realloc(vms_fmatch,
44d845c
  		sizeof(char **) * vms_match_alloced);
44d845c
  	if (!vms_fmatch)
44d845c
  	    return 0;
44d845c
***************
44d845c
*** 460,466 ****
44d845c
  	    if (--files_free < 1)
44d845c
  	    {
44d845c
  		files_alloced += EXPL_ALLOC_INC;
44d845c
! 		*file = (char_u **)realloc(*file,
44d845c
  		    sizeof(char_u **) * files_alloced);
44d845c
  		if (*file == NULL)
44d845c
  		{
44d845c
--- 460,466 ----
44d845c
  	    if (--files_free < 1)
44d845c
  	    {
44d845c
  		files_alloced += EXPL_ALLOC_INC;
44d845c
! 		*file = (char_u **)vim_realloc(*file,
44d845c
  		    sizeof(char_u **) * files_alloced);
44d845c
  		if (*file == NULL)
44d845c
  		{
44d845c
***************
44d845c
*** 614,627 ****
44d845c
      {
44d845c
  	buflen = len + 128;
44d845c
  	if (buf)
44d845c
! 	    buf = (char *)realloc(buf, buflen);
44d845c
  	else
44d845c
! 	    buf = (char *)calloc(buflen, sizeof(char));
44d845c
      }
44d845c
  
44d845c
  #ifdef DEBUG
44d845c
       char		 *tmpbuf = NULL;
44d845c
!      tmpbuf = (char *)calloc(buflen, sizeof(char));
44d845c
       strcpy(tmpbuf, instring);
44d845c
  #endif
44d845c
  
44d845c
--- 614,627 ----
44d845c
      {
44d845c
  	buflen = len + 128;
44d845c
  	if (buf)
44d845c
! 	    buf = (char *)vim_realloc(buf, buflen);
44d845c
  	else
44d845c
! 	    buf = (char *)alloc(buflen * sizeof(char));
44d845c
      }
44d845c
  
44d845c
  #ifdef DEBUG
44d845c
       char		 *tmpbuf = NULL;
44d845c
!      tmpbuf = (char *)alloc(buflen * sizeof(char));
44d845c
       strcpy(tmpbuf, instring);
44d845c
  #endif
44d845c
  
44d845c
*** ../vim-7.2.035/src/os_w32exe.c	Fri Jul  1 00:06:20 2005
44d845c
--- src/os_w32exe.c	Wed Nov 12 11:45:43 2008
44d845c
***************
44d845c
*** 129,135 ****
44d845c
  errout:
44d845c
  #endif
44d845c
      free(argv);
44d845c
!     free(tofree);
44d845c
  #ifdef FEAT_MBYTE
44d845c
      free_cmd_argsW();
44d845c
  #endif
44d845c
--- 129,136 ----
44d845c
  errout:
44d845c
  #endif
44d845c
      free(argv);
44d845c
!     if (tofree != NULL)
44d845c
! 	free(tofree);
44d845c
  #ifdef FEAT_MBYTE
44d845c
      free_cmd_argsW();
44d845c
  #endif
44d845c
*** ../vim-7.2.035/src/os_win16.c	Wed Jun 25 00:49:34 2008
44d845c
--- src/os_win16.c	Wed Nov 12 11:45:53 2008
44d845c
***************
44d845c
*** 121,127 ****
44d845c
      pmain(argc, argv);
44d845c
  
44d845c
      free(argv);
44d845c
!     free(tofree);
44d845c
  
44d845c
      return 0;
44d845c
  }
44d845c
--- 121,128 ----
44d845c
      pmain(argc, argv);
44d845c
  
44d845c
      free(argv);
44d845c
!     if (tofree != NULL)
44d845c
! 	free(tofree);
44d845c
  
44d845c
      return 0;
44d845c
  }
44d845c
*** ../vim-7.2.035/src/version.c	Wed Nov 12 13:07:48 2008
44d845c
--- src/version.c	Wed Nov 12 13:28:51 2008
44d845c
***************
44d845c
*** 678,679 ****
44d845c
--- 678,681 ----
44d845c
  {   /* Add new patch number below this line */
44d845c
+ /**/
44d845c
+     36,
44d845c
  /**/
44d845c
44d845c
-- 
44d845c
hundred-and-one symptoms of being an internet addict:
44d845c
239. You think "surfing" is something you do on dry land.
44d845c
44d845c
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
44d845c
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
44d845c
\\\        download, build and distribute -- http://www.A-A-P.org        ///
44d845c
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///