Skip to content

Commit faebc8f

Browse files
committed
updated for version 7.3.697
Problem: Leaking resources when setting GUI font. Solution: Free the font. (Ken Takata)
1 parent 9600a7a commit faebc8f

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/syntax.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static GuiFont font_name2handle __ARGS((char_u *name));
105105
# ifdef FEAT_XFONTSET
106106
static GuiFontset fontset_name2handle __ARGS((char_u *name, int fixed_width));
107107
# endif
108-
static void hl_do_font __ARGS((int idx, char_u *arg, int do_normal, int do_menu, int do_tooltip));
108+
static void hl_do_font __ARGS((int idx, char_u *arg, int do_normal, int do_menu, int do_tooltip, int free_font));
109109
#endif
110110

111111
/*
@@ -7259,14 +7259,13 @@ do_highlight(line, forceit, init)
72597259
HL_TABLE()[idx].sg_fontset = NOFONTSET;
72607260
# endif
72617261
hl_do_font(idx, arg, is_normal_group, is_menu_group,
7262-
is_tooltip_group);
7262+
is_tooltip_group, FALSE);
72637263

72647264
# ifdef FEAT_XFONTSET
72657265
if (HL_TABLE()[idx].sg_fontset != NOFONTSET)
72667266
{
7267-
/* New fontset was accepted. Free the old one, if there was
7268-
* one.
7269-
*/
7267+
/* New fontset was accepted. Free the old one, if there
7268+
* was one. */
72707269
gui_mch_free_fontset(temp_sg_fontset);
72717270
vim_free(HL_TABLE()[idx].sg_font_name);
72727271
HL_TABLE()[idx].sg_font_name = vim_strsave(arg);
@@ -7277,8 +7276,7 @@ do_highlight(line, forceit, init)
72777276
if (HL_TABLE()[idx].sg_font != NOFONT)
72787277
{
72797278
/* New font was accepted. Free the old one, if there was
7280-
* one.
7281-
*/
7279+
* one. */
72827280
gui_mch_free_font(temp_sg_font);
72837281
vim_free(HL_TABLE()[idx].sg_font_name);
72847282
HL_TABLE()[idx].sg_font_name = vim_strsave(arg);
@@ -8064,12 +8062,13 @@ fontset_name2handle(name, fixed_width)
80648062
* Get the font or fontset for one highlight group.
80658063
*/
80668064
static void
8067-
hl_do_font(idx, arg, do_normal, do_menu, do_tooltip)
8065+
hl_do_font(idx, arg, do_normal, do_menu, do_tooltip, free_font)
80688066
int idx;
80698067
char_u *arg;
80708068
int do_normal; /* set normal font */
80718069
int do_menu UNUSED; /* set menu font */
80728070
int do_tooltip UNUSED; /* set tooltip font */
8071+
int free_font; /* free current font/fontset */
80738072
{
80748073
# ifdef FEAT_XFONTSET
80758074
/* If 'guifontset' is not empty, first try using the name as a
@@ -8083,6 +8082,8 @@ hl_do_font(idx, arg, do_normal, do_menu, do_tooltip)
80838082
|| do_tooltip
80848083
# endif
80858084
)
8085+
if (free_fontset)
8086+
gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset);
80868087
HL_TABLE()[idx].sg_fontset = fontset_name2handle(arg, 0
80878088
# ifdef FONTSET_ALWAYS
80888089
|| do_menu
@@ -8093,8 +8094,8 @@ hl_do_font(idx, arg, do_normal, do_menu, do_tooltip)
80938094
);
80948095
if (HL_TABLE()[idx].sg_fontset != NOFONTSET)
80958096
{
8096-
/* If it worked and it's the Normal group, use it as the
8097-
* normal fontset. Same for the Menu group. */
8097+
/* If it worked and it's the Normal group, use it as the normal
8098+
* fontset. Same for the Menu group. */
80988099
if (do_normal)
80998100
gui_init_font(arg, TRUE);
81008101
# if (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) && defined(FEAT_MENU)
@@ -8126,6 +8127,8 @@ hl_do_font(idx, arg, do_normal, do_menu, do_tooltip)
81268127
else
81278128
# endif
81288129
{
8130+
if (free_font)
8131+
gui_mch_free_font(HL_TABLE()[idx].sg_font);
81298132
HL_TABLE()[idx].sg_font = font_name2handle(arg);
81308133
/* If it worked and it's the Normal group, use it as the
81318134
* normal font. Same for the Menu group. */
@@ -9162,7 +9165,7 @@ gui_do_one_color(idx, do_menu, do_tooltip)
91629165
if (HL_TABLE()[idx].sg_font_name != NULL)
91639166
{
91649167
hl_do_font(idx, HL_TABLE()[idx].sg_font_name, FALSE, do_menu,
9165-
do_tooltip);
9168+
do_tooltip, TRUE);
91669169
didit = TRUE;
91679170
}
91689171
if (HL_TABLE()[idx].sg_gui_fg_name != NULL)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ static char *(features[]) =
719719

720720
static int included_patches[] =
721721
{ /* Add new patch number below this line */
722+
/**/
723+
697,
722724
/**/
723725
696,
724726
/**/

0 commit comments

Comments
 (0)