Karsten Hopp cb6b96
To: vim_dev@googlegroups.com
Karsten Hopp cb6b96
Subject: Patch 7.3.697
Karsten Hopp cb6b96
Fcc: outbox
Karsten Hopp cb6b96
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp cb6b96
Mime-Version: 1.0
Karsten Hopp cb6b96
Content-Type: text/plain; charset=UTF-8
Karsten Hopp cb6b96
Content-Transfer-Encoding: 8bit
Karsten Hopp cb6b96
------------
Karsten Hopp cb6b96
Karsten Hopp cb6b96
Patch 7.3.697
Karsten Hopp cb6b96
Problem:    Leaking resources when setting GUI font.
Karsten Hopp cb6b96
Solution:   Free the font. (Ken Takata)
Karsten Hopp cb6b96
Files:      src/syntax.c
Karsten Hopp cb6b96
Karsten Hopp cb6b96
Karsten Hopp cb6b96
*** ../vim-7.3.696/src/syntax.c	2012-07-19 17:39:01.000000000 +0200
Karsten Hopp cb6b96
--- src/syntax.c	2012-10-21 01:37:19.000000000 +0200
Karsten Hopp cb6b96
***************
Karsten Hopp cb6b96
*** 105,111 ****
Karsten Hopp cb6b96
  # ifdef FEAT_XFONTSET
Karsten Hopp cb6b96
  static GuiFontset fontset_name2handle __ARGS((char_u *name, int fixed_width));
Karsten Hopp cb6b96
  # endif
Karsten Hopp cb6b96
! static void hl_do_font __ARGS((int idx, char_u *arg, int do_normal, int do_menu, int do_tooltip));
Karsten Hopp cb6b96
  #endif
Karsten Hopp cb6b96
  
Karsten Hopp cb6b96
  /*
Karsten Hopp cb6b96
--- 105,111 ----
Karsten Hopp cb6b96
  # ifdef FEAT_XFONTSET
Karsten Hopp cb6b96
  static GuiFontset fontset_name2handle __ARGS((char_u *name, int fixed_width));
Karsten Hopp cb6b96
  # endif
Karsten Hopp cb6b96
! static void hl_do_font __ARGS((int idx, char_u *arg, int do_normal, int do_menu, int do_tooltip, int free_font));
Karsten Hopp cb6b96
  #endif
Karsten Hopp cb6b96
  
Karsten Hopp cb6b96
  /*
Karsten Hopp cb6b96
***************
Karsten Hopp cb6b96
*** 7259,7272 ****
Karsten Hopp cb6b96
  		HL_TABLE()[idx].sg_fontset = NOFONTSET;
Karsten Hopp cb6b96
  # endif
Karsten Hopp cb6b96
  		hl_do_font(idx, arg, is_normal_group, is_menu_group,
Karsten Hopp cb6b96
! 							    is_tooltip_group);
Karsten Hopp cb6b96
  
Karsten Hopp cb6b96
  # ifdef FEAT_XFONTSET
Karsten Hopp cb6b96
  		if (HL_TABLE()[idx].sg_fontset != NOFONTSET)
Karsten Hopp cb6b96
  		{
Karsten Hopp cb6b96
! 		    /* New fontset was accepted. Free the old one, if there was
Karsten Hopp cb6b96
! 		     * one.
Karsten Hopp cb6b96
! 		     */
Karsten Hopp cb6b96
  		    gui_mch_free_fontset(temp_sg_fontset);
Karsten Hopp cb6b96
  		    vim_free(HL_TABLE()[idx].sg_font_name);
Karsten Hopp cb6b96
  		    HL_TABLE()[idx].sg_font_name = vim_strsave(arg);
Karsten Hopp cb6b96
--- 7259,7271 ----
Karsten Hopp cb6b96
  		HL_TABLE()[idx].sg_fontset = NOFONTSET;
Karsten Hopp cb6b96
  # endif
Karsten Hopp cb6b96
  		hl_do_font(idx, arg, is_normal_group, is_menu_group,
Karsten Hopp cb6b96
! 						     is_tooltip_group, FALSE);
Karsten Hopp cb6b96
  
Karsten Hopp cb6b96
  # ifdef FEAT_XFONTSET
Karsten Hopp cb6b96
  		if (HL_TABLE()[idx].sg_fontset != NOFONTSET)
Karsten Hopp cb6b96
  		{
Karsten Hopp cb6b96
! 		    /* New fontset was accepted. Free the old one, if there
Karsten Hopp cb6b96
! 		     * was one. */
Karsten Hopp cb6b96
  		    gui_mch_free_fontset(temp_sg_fontset);
Karsten Hopp cb6b96
  		    vim_free(HL_TABLE()[idx].sg_font_name);
Karsten Hopp cb6b96
  		    HL_TABLE()[idx].sg_font_name = vim_strsave(arg);
Karsten Hopp cb6b96
***************
Karsten Hopp cb6b96
*** 7277,7284 ****
Karsten Hopp cb6b96
  		if (HL_TABLE()[idx].sg_font != NOFONT)
Karsten Hopp cb6b96
  		{
Karsten Hopp cb6b96
  		    /* New font was accepted. Free the old one, if there was
Karsten Hopp cb6b96
! 		     * one.
Karsten Hopp cb6b96
! 		     */
Karsten Hopp cb6b96
  		    gui_mch_free_font(temp_sg_font);
Karsten Hopp cb6b96
  		    vim_free(HL_TABLE()[idx].sg_font_name);
Karsten Hopp cb6b96
  		    HL_TABLE()[idx].sg_font_name = vim_strsave(arg);
Karsten Hopp cb6b96
--- 7276,7282 ----
Karsten Hopp cb6b96
  		if (HL_TABLE()[idx].sg_font != NOFONT)
Karsten Hopp cb6b96
  		{
Karsten Hopp cb6b96
  		    /* New font was accepted. Free the old one, if there was
Karsten Hopp cb6b96
! 		     * one. */
Karsten Hopp cb6b96
  		    gui_mch_free_font(temp_sg_font);
Karsten Hopp cb6b96
  		    vim_free(HL_TABLE()[idx].sg_font_name);
Karsten Hopp cb6b96
  		    HL_TABLE()[idx].sg_font_name = vim_strsave(arg);
Karsten Hopp cb6b96
***************
Karsten Hopp cb6b96
*** 8064,8075 ****
Karsten Hopp cb6b96
   * Get the font or fontset for one highlight group.
Karsten Hopp cb6b96
   */
Karsten Hopp cb6b96
      static void
Karsten Hopp cb6b96
! hl_do_font(idx, arg, do_normal, do_menu, do_tooltip)
Karsten Hopp cb6b96
      int		idx;
Karsten Hopp cb6b96
      char_u	*arg;
Karsten Hopp cb6b96
      int		do_normal;		/* set normal font */
Karsten Hopp cb6b96
      int		do_menu UNUSED;		/* set menu font */
Karsten Hopp cb6b96
      int		do_tooltip UNUSED;	/* set tooltip font */
Karsten Hopp cb6b96
  {
Karsten Hopp cb6b96
  # ifdef FEAT_XFONTSET
Karsten Hopp cb6b96
      /* If 'guifontset' is not empty, first try using the name as a
Karsten Hopp cb6b96
--- 8062,8074 ----
Karsten Hopp cb6b96
   * Get the font or fontset for one highlight group.
Karsten Hopp cb6b96
   */
Karsten Hopp cb6b96
      static void
Karsten Hopp cb6b96
! hl_do_font(idx, arg, do_normal, do_menu, do_tooltip, free_font)
Karsten Hopp cb6b96
      int		idx;
Karsten Hopp cb6b96
      char_u	*arg;
Karsten Hopp cb6b96
      int		do_normal;		/* set normal font */
Karsten Hopp cb6b96
      int		do_menu UNUSED;		/* set menu font */
Karsten Hopp cb6b96
      int		do_tooltip UNUSED;	/* set tooltip font */
Karsten Hopp cb6b96
+     int		free_font;		/* free current font/fontset */
Karsten Hopp cb6b96
  {
Karsten Hopp cb6b96
  # ifdef FEAT_XFONTSET
Karsten Hopp cb6b96
      /* If 'guifontset' is not empty, first try using the name as a
Karsten Hopp cb6b96
***************
Karsten Hopp cb6b96
*** 8083,8088 ****
Karsten Hopp cb6b96
--- 8082,8089 ----
Karsten Hopp cb6b96
  	|| do_tooltip
Karsten Hopp cb6b96
  #  endif
Karsten Hopp cb6b96
  	    )
Karsten Hopp cb6b96
+ 	if (free_fontset)
Karsten Hopp cb6b96
+ 	    gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset);
Karsten Hopp cb6b96
  	HL_TABLE()[idx].sg_fontset = fontset_name2handle(arg, 0
Karsten Hopp cb6b96
  #  ifdef FONTSET_ALWAYS
Karsten Hopp cb6b96
  		|| do_menu
Karsten Hopp cb6b96
***************
Karsten Hopp cb6b96
*** 8093,8100 ****
Karsten Hopp cb6b96
  		);
Karsten Hopp cb6b96
      if (HL_TABLE()[idx].sg_fontset != NOFONTSET)
Karsten Hopp cb6b96
      {
Karsten Hopp cb6b96
! 	/* If it worked and it's the Normal group, use it as the
Karsten Hopp cb6b96
! 	 * normal fontset.  Same for the Menu group. */
Karsten Hopp cb6b96
  	if (do_normal)
Karsten Hopp cb6b96
  	    gui_init_font(arg, TRUE);
Karsten Hopp cb6b96
  #   if (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) && defined(FEAT_MENU)
Karsten Hopp cb6b96
--- 8094,8101 ----
Karsten Hopp cb6b96
  		);
Karsten Hopp cb6b96
      if (HL_TABLE()[idx].sg_fontset != NOFONTSET)
Karsten Hopp cb6b96
      {
Karsten Hopp cb6b96
! 	/* If it worked and it's the Normal group, use it as the normal
Karsten Hopp cb6b96
! 	 * fontset.  Same for the Menu group. */
Karsten Hopp cb6b96
  	if (do_normal)
Karsten Hopp cb6b96
  	    gui_init_font(arg, TRUE);
Karsten Hopp cb6b96
  #   if (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) && defined(FEAT_MENU)
Karsten Hopp cb6b96
***************
Karsten Hopp cb6b96
*** 8126,8131 ****
Karsten Hopp cb6b96
--- 8127,8134 ----
Karsten Hopp cb6b96
      else
Karsten Hopp cb6b96
  # endif
Karsten Hopp cb6b96
      {
Karsten Hopp cb6b96
+ 	if (free_font)
Karsten Hopp cb6b96
+ 	    gui_mch_free_font(HL_TABLE()[idx].sg_font);
Karsten Hopp cb6b96
  	HL_TABLE()[idx].sg_font = font_name2handle(arg);
Karsten Hopp cb6b96
  	/* If it worked and it's the Normal group, use it as the
Karsten Hopp cb6b96
  	 * normal font.  Same for the Menu group. */
Karsten Hopp cb6b96
***************
Karsten Hopp cb6b96
*** 9162,9168 ****
Karsten Hopp cb6b96
      if (HL_TABLE()[idx].sg_font_name != NULL)
Karsten Hopp cb6b96
      {
Karsten Hopp cb6b96
  	hl_do_font(idx, HL_TABLE()[idx].sg_font_name, FALSE, do_menu,
Karsten Hopp cb6b96
! 		   do_tooltip);
Karsten Hopp cb6b96
  	didit = TRUE;
Karsten Hopp cb6b96
      }
Karsten Hopp cb6b96
      if (HL_TABLE()[idx].sg_gui_fg_name != NULL)
Karsten Hopp cb6b96
--- 9165,9171 ----
Karsten Hopp cb6b96
      if (HL_TABLE()[idx].sg_font_name != NULL)
Karsten Hopp cb6b96
      {
Karsten Hopp cb6b96
  	hl_do_font(idx, HL_TABLE()[idx].sg_font_name, FALSE, do_menu,
Karsten Hopp cb6b96
! 							    do_tooltip, TRUE);
Karsten Hopp cb6b96
  	didit = TRUE;
Karsten Hopp cb6b96
      }
Karsten Hopp cb6b96
      if (HL_TABLE()[idx].sg_gui_fg_name != NULL)
Karsten Hopp cb6b96
*** ../vim-7.3.696/src/version.c	2012-10-21 01:21:53.000000000 +0200
Karsten Hopp cb6b96
--- src/version.c	2012-10-21 01:27:55.000000000 +0200
Karsten Hopp cb6b96
***************
Karsten Hopp cb6b96
*** 721,722 ****
Karsten Hopp cb6b96
--- 721,724 ----
Karsten Hopp cb6b96
  {   /* Add new patch number below this line */
Karsten Hopp cb6b96
+ /**/
Karsten Hopp cb6b96
+     697,
Karsten Hopp cb6b96
  /**/
Karsten Hopp cb6b96
Karsten Hopp cb6b96
-- 
Karsten Hopp cb6b96
BEDEVERE: Wait.  Wait ... tell me, what also floats on water?
Karsten Hopp cb6b96
ALL:      Bread?  No, no, no.  Apples .... gravy ... very small rocks ...
Karsten Hopp cb6b96
ARTHUR:   A duck.
Karsten Hopp cb6b96
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Karsten Hopp cb6b96
Karsten Hopp cb6b96
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp cb6b96
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp cb6b96
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp cb6b96
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///