fix(options): properly free string options (#19510)

This commit is contained in:
zeertzjq 2022-07-27 07:26:32 +08:00 committed by GitHub
parent 890d4023cd
commit 79872f3770
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 8 deletions

View File

@ -1423,7 +1423,7 @@ void diff_win_options(win_T *wp, int addbuf)
} }
wp->w_p_fdc_save = vim_strsave(wp->w_p_fdc); wp->w_p_fdc_save = vim_strsave(wp->w_p_fdc);
} }
xfree(wp->w_p_fdc); free_string_option(wp->w_p_fdc);
wp->w_p_fdc = (char_u *)xstrdup("2"); wp->w_p_fdc = (char_u *)xstrdup("2");
assert(diff_foldcolumn >= 0 && diff_foldcolumn <= 9); assert(diff_foldcolumn >= 0 && diff_foldcolumn <= 9);
snprintf((char *)wp->w_p_fdc, STRLEN(wp->w_p_fdc) + 1, "%d", diff_foldcolumn); snprintf((char *)wp->w_p_fdc, STRLEN(wp->w_p_fdc) + 1, "%d", diff_foldcolumn);

View File

@ -451,7 +451,7 @@ void terminal_enter(void)
if (save_curwin == curwin->handle) { // Else: window was closed. if (save_curwin == curwin->handle) { // Else: window was closed.
curwin->w_p_cul = save_w_p_cul; curwin->w_p_cul = save_w_p_cul;
if (save_w_p_culopt) { if (save_w_p_culopt) {
xfree(curwin->w_p_culopt); free_string_option(curwin->w_p_culopt);
curwin->w_p_culopt = save_w_p_culopt; curwin->w_p_culopt = save_w_p_culopt;
} }
curwin->w_p_culopt_flags = save_w_p_culopt_flags; curwin->w_p_culopt_flags = save_w_p_culopt_flags;
@ -459,7 +459,7 @@ void terminal_enter(void)
curwin->w_p_so = save_w_p_so; curwin->w_p_so = save_w_p_so;
curwin->w_p_siso = save_w_p_siso; curwin->w_p_siso = save_w_p_siso;
} else if (save_w_p_culopt) { } else if (save_w_p_culopt) {
xfree(save_w_p_culopt); free_string_option(save_w_p_culopt);
} }
// draw the unfocused cursor // draw the unfocused cursor

View File

@ -726,31 +726,31 @@ void win_set_minimal_style(win_T *wp)
wp->w_p_fcs = ((*old == NUL) wp->w_p_fcs = ((*old == NUL)
? (char_u *)xstrdup("eob: ") ? (char_u *)xstrdup("eob: ")
: concat_str(old, (char_u *)",eob: ")); : concat_str(old, (char_u *)",eob: "));
xfree(old); free_string_option(old);
} }
if (wp->w_hl_ids[HLF_EOB] != -1) { if (wp->w_hl_ids[HLF_EOB] != -1) {
char_u *old = wp->w_p_winhl; char_u *old = wp->w_p_winhl;
wp->w_p_winhl = ((*old == NUL) wp->w_p_winhl = ((*old == NUL)
? (char_u *)xstrdup("EndOfBuffer:") ? (char_u *)xstrdup("EndOfBuffer:")
: concat_str(old, (char_u *)",EndOfBuffer:")); : concat_str(old, (char_u *)",EndOfBuffer:"));
xfree(old); free_string_option(old);
} }
// signcolumn: use 'auto' // signcolumn: use 'auto'
if (wp->w_p_scl[0] != 'a' || STRLEN(wp->w_p_scl) >= 8) { if (wp->w_p_scl[0] != 'a' || STRLEN(wp->w_p_scl) >= 8) {
xfree(wp->w_p_scl); free_string_option(wp->w_p_scl);
wp->w_p_scl = (char_u *)xstrdup("auto"); wp->w_p_scl = (char_u *)xstrdup("auto");
} }
// foldcolumn: use '0' // foldcolumn: use '0'
if (wp->w_p_fdc[0] != '0') { if (wp->w_p_fdc[0] != '0') {
xfree(wp->w_p_fdc); free_string_option(wp->w_p_fdc);
wp->w_p_fdc = (char_u *)xstrdup("0"); wp->w_p_fdc = (char_u *)xstrdup("0");
} }
// colorcolumn: cleared // colorcolumn: cleared
if (wp->w_p_cc != NULL && *wp->w_p_cc != NUL) { if (wp->w_p_cc != NULL && *wp->w_p_cc != NUL) {
xfree(wp->w_p_cc); free_string_option(wp->w_p_cc);
wp->w_p_cc = (char_u *)xstrdup(""); wp->w_p_cc = (char_u *)xstrdup("");
} }
} }

View File

@ -18,6 +18,7 @@ local run = helpers.run
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local tbl_contains = global_helpers.tbl_contains local tbl_contains = global_helpers.tbl_contains
local curbuf, curwin, curtab = helpers.curbuf, helpers.curwin, helpers.curtab local curbuf, curwin, curtab = helpers.curbuf, helpers.curwin, helpers.curtab
local NIL = helpers.NIL
describe('float window', function() describe('float window', function()
before_each(function() before_each(function()
@ -420,6 +421,15 @@ describe('float window', function()
eq(winids, eval('winids')) eq(winids, eval('winids'))
end) end)
it("no segfault when setting minimal style after clearing local 'fillchars' #19510", function()
local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1}
local float_win = meths.open_win(0, true, float_opts)
meths.win_set_option(float_win, 'fillchars', NIL)
float_opts.style = 'minimal'
meths.win_set_config(float_win, float_opts)
assert_alive()
end)
describe('with only one tabpage,', function() describe('with only one tabpage,', function()
local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1} local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1}
local old_buf, old_win local old_buf, old_win