Skip to content

Commit 09d1d51

Browse files
committed
patch 8.0.1759: memory leak from duplicate options
Problem: Memory leak from duplicate options. (Yegappan Lakshmanan) Solution: Don't set the default value twice.
1 parent 24a2d72 commit 09d1d51

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

‎src/option.c‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3805,17 +3805,23 @@ set_option_default(
38053805
dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
38063806
if (flags & P_STRING)
38073807
{
3808-
/* Use set_string_option_direct() for local options to handle
3809-
* freeing and allocating the value. */
3810-
if (options[opt_idx].indir != PV_NONE)
3811-
set_string_option_direct(NULL, opt_idx,
3812-
options[opt_idx].def_val[dvi], opt_flags, 0);
3813-
else
3808+
/* skip 'termkey' and 'termsize, they are duplicates of
3809+
* 'termwinkey' and 'termwinsize' */
3810+
if (STRCMP(options[opt_idx].fullname, "termkey") != 0
3811+
&& STRCMP(options[opt_idx].fullname, "termsize") != 0)
38143812
{
3815-
if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3816-
free_string_option(*(char_u **)(varp));
3817-
*(char_u **)varp = options[opt_idx].def_val[dvi];
3818-
options[opt_idx].flags &= ~P_ALLOCED;
3813+
/* Use set_string_option_direct() for local options to handle
3814+
* freeing and allocating the value. */
3815+
if (options[opt_idx].indir != PV_NONE)
3816+
set_string_option_direct(NULL, opt_idx,
3817+
options[opt_idx].def_val[dvi], opt_flags, 0);
3818+
else
3819+
{
3820+
if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3821+
free_string_option(*(char_u **)(varp));
3822+
*(char_u **)varp = options[opt_idx].def_val[dvi];
3823+
options[opt_idx].flags &= ~P_ALLOCED;
3824+
}
38193825
}
38203826
}
38213827
else if (flags & P_NUM)

‎src/version.c‎

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

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1759,
764766
/**/
765767
1758,
766768
/**/

0 commit comments

Comments
 (0)