81c2858
To: vim-dev@vim.org
81c2858
Subject: Patch 7.2.238
81c2858
Fcc: outbox
81c2858
From: Bram Moolenaar <Bram@moolenaar.net>
81c2858
Mime-Version: 1.0
81c2858
Content-Type: text/plain; charset=UTF-8
81c2858
Content-Transfer-Encoding: 8bit
81c2858
------------
81c2858
81c2858
Patch 7.2.238
81c2858
Problem:    Leaking memory when setting term to "builtin_dumb".
81c2858
Solution:   Free memory when resetting term option t_Co.
81c2858
Files:	    src/option.c, src/proto/option.pro, src/term.c
81c2858
81c2858
81c2858
*** ../vim-7.2.237/src/option.c	2009-06-16 17:50:56.000000000 +0200
81c2858
--- src/option.c	2009-07-22 12:49:19.000000000 +0200
81c2858
***************
81c2858
*** 403,410 ****
81c2858
  #define P_NUM		0x02	/* the option is numeric */
81c2858
  #define P_STRING	0x04	/* the option is a string */
81c2858
  #define P_ALLOCED	0x08	/* the string option is in allocated memory,
81c2858
! 				    must use vim_free() when assigning new
81c2858
! 				    value. Not set if default is the same. */
81c2858
  #define P_EXPAND	0x10	/* environment expansion.  NOTE: P_EXPAND can
81c2858
  				   never be used for local or hidden options! */
81c2858
  #define P_NODEFAULT	0x40	/* don't set to default value */
81c2858
--- 403,411 ----
81c2858
  #define P_NUM		0x02	/* the option is numeric */
81c2858
  #define P_STRING	0x04	/* the option is a string */
81c2858
  #define P_ALLOCED	0x08	/* the string option is in allocated memory,
81c2858
! 				   must use free_string_option() when
81c2858
! 				   assigning new value. Not set if default is
81c2858
! 				   the same. */
81c2858
  #define P_EXPAND	0x10	/* environment expansion.  NOTE: P_EXPAND can
81c2858
  				   never be used for local or hidden options! */
81c2858
  #define P_NODEFAULT	0x40	/* don't set to default value */
81c2858
***************
81c2858
*** 8927,8932 ****
81c2858
--- 8928,8955 ----
81c2858
  }
81c2858
  
81c2858
  /*
81c2858
+  * Free the string for one term option, if it was allocated.
81c2858
+  * Set the string to empty_option and clear allocated flag.
81c2858
+  * "var" points to the option value.
81c2858
+  */
81c2858
+     void
81c2858
+ free_one_termoption(var)
81c2858
+     char_u *var;
81c2858
+ {
81c2858
+     struct vimoption   *p;
81c2858
+ 
81c2858
+     for (p = &options[0]; p->fullname != NULL; p++)
81c2858
+ 	if (p->var == var)
81c2858
+ 	{
81c2858
+ 	    if (p->flags & P_ALLOCED)
81c2858
+ 		free_string_option(*(char_u **)(p->var));
81c2858
+ 	    *(char_u **)(p->var) = empty_option;
81c2858
+ 	    p->flags &= ~P_ALLOCED;
81c2858
+ 	    break;
81c2858
+ 	}
81c2858
+ }
81c2858
+ 
81c2858
+ /*
81c2858
   * Set the terminal option defaults to the current value.
81c2858
   * Used after setting the terminal name.
81c2858
   */
81c2858
*** ../vim-7.2.237/src/proto/option.pro	2009-02-21 20:27:00.000000000 +0100
81c2858
--- src/proto/option.pro	2009-07-22 12:52:31.000000000 +0200
81c2858
***************
81c2858
*** 29,34 ****
81c2858
--- 29,35 ----
81c2858
  int makefoldset __ARGS((FILE *fd));
81c2858
  void clear_termoptions __ARGS((void));
81c2858
  void free_termoptions __ARGS((void));
81c2858
+ void free_one_termoption __ARGS((char_u *var));
81c2858
  void set_term_defaults __ARGS((void));
81c2858
  void comp_col __ARGS((void));
81c2858
  char_u *get_equalprg __ARGS((void));
81c2858
*** ../vim-7.2.237/src/term.c	2009-06-16 14:31:56.000000000 +0200
81c2858
--- src/term.c	2009-07-22 13:19:59.000000000 +0200
81c2858
***************
81c2858
*** 2881,2887 ****
81c2858
  
81c2858
  	/* if 'Sb' and 'AB' are not defined, reset "Co" */
81c2858
  	if (*T_CSB == NUL && *T_CAB == NUL)
81c2858
! 	    T_CCO = empty_option;
81c2858
  
81c2858
  	/* Set 'weirdinvert' according to value of 't_xs' */
81c2858
  	p_wiv = (*T_XS != NUL);
81c2858
--- 2881,2887 ----
81c2858
  
81c2858
  	/* if 'Sb' and 'AB' are not defined, reset "Co" */
81c2858
  	if (*T_CSB == NUL && *T_CAB == NUL)
81c2858
! 	    free_one_termoption(T_CCO);
81c2858
  
81c2858
  	/* Set 'weirdinvert' according to value of 't_xs' */
81c2858
  	p_wiv = (*T_XS != NUL);
81c2858
*** ../vim-7.2.237/src/version.c	2009-07-22 13:27:50.000000000 +0200
81c2858
--- src/version.c	2009-07-22 14:25:44.000000000 +0200
81c2858
***************
81c2858
*** 678,679 ****
81c2858
--- 678,681 ----
81c2858
  {   /* Add new patch number below this line */
81c2858
+ /**/
81c2858
+     238,
81c2858
  /**/
81c2858
81c2858
-- 
81c2858
hundred-and-one symptoms of being an internet addict:
81c2858
95. Only communication in your household is through email.
81c2858
81c2858
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
81c2858
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
81c2858
\\\        download, build and distribute -- http://www.A-A-P.org        ///
81c2858
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///