Skip to content

Commit

Permalink
fix(options): properly free string option
Browse files Browse the repository at this point in the history
  • Loading branch information
zeertzjq committed Jul 26, 2022
1 parent 1a07044 commit 4d8e514
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/nvim/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ void diff_win_options(win_T *wp, int addbuf)
}
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");
assert(diff_foldcolumn >= 0 && diff_foldcolumn <= 9);
snprintf((char *)wp->w_p_fdc, STRLEN(wp->w_p_fdc) + 1, "%d", diff_foldcolumn);
Expand Down
4 changes: 2 additions & 2 deletions src/nvim/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,15 @@ void terminal_enter(void)
if (save_curwin == curwin->handle) { // Else: window was closed.
curwin->w_p_cul = save_w_p_cul;
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_flags = save_w_p_culopt_flags;
curwin->w_p_cuc = save_w_p_cuc;
curwin->w_p_so = save_w_p_so;
curwin->w_p_siso = save_w_p_siso;
} else if (save_w_p_culopt) {
xfree(save_w_p_culopt);
free_string_option(save_w_p_culopt);
}

// draw the unfocused cursor
Expand Down
10 changes: 5 additions & 5 deletions src/nvim/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,31 +726,31 @@ void win_set_minimal_style(win_T *wp)
wp->w_p_fcs = ((*old == NUL)
? (char_u *)xstrdup("eob: ")
: concat_str(old, (char_u *)",eob: "));
xfree(old);
free_string_option(old);
}
if (wp->w_hl_ids[HLF_EOB] != -1) {
char_u *old = wp->w_p_winhl;
wp->w_p_winhl = ((*old == NUL)
? (char_u *)xstrdup("EndOfBuffer:")
: concat_str(old, (char_u *)",EndOfBuffer:"));
xfree(old);
free_string_option(old);
}

// signcolumn: use 'auto'
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");
}

// foldcolumn: use '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");
}

// colorcolumn: cleared
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("");
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/functional/ui/float_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local run = helpers.run
local pcall_err = helpers.pcall_err
local tbl_contains = global_helpers.tbl_contains
local curbuf, curwin, curtab = helpers.curbuf, helpers.curwin, helpers.curtab
local NIL = helpers.NIL

describe('float window', function()
before_each(function()
Expand Down Expand Up @@ -420,6 +421,15 @@ describe('float window', function()
eq(winids, eval('winids'))
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()
local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1}
local old_buf, old_win
Expand Down

0 comments on commit 4d8e514

Please sign in to comment.