vim-patch:9.1.1573: Memory leak when pressing Ctrl-D in cmdline mode

Problem:  Memory leak when pressing Ctrl-D in cmdline mode
          (after 9.1.1571).
Solution: Free prev_cmdbuff before assigning to it.
          (zeertzjq).

Existing tests already cover this. This change fixes the CI failure.

closes: vim/vim#17807

c02bef26fd
This commit is contained in:
zeertzjq
2025-07-21 07:15:56 +08:00
parent bbc368dfce
commit 22d1fb8c01

View File

@@ -1021,7 +1021,9 @@ theend:
static int command_line_check(VimState *state) static int command_line_check(VimState *state)
{ {
CommandLineState *s = (CommandLineState *)state; CommandLineState *s = (CommandLineState *)state;
s->prev_cmdpos = ccline.cmdpos; s->prev_cmdpos = ccline.cmdpos;
XFREE_CLEAR(s->prev_cmdbuff);
redir_off = true; // Don't redirect the typed command. redir_off = true; // Don't redirect the typed command.
// Repeated, because a ":redir" inside // Repeated, because a ":redir" inside
@@ -2309,7 +2311,6 @@ static int command_line_not_changed(CommandLineState *s)
// changed in the past. // changed in the past.
// Enter command_line_changed() when the command line did change. // Enter command_line_changed() when the command line did change.
if (!s->is_state.incsearch_postponed) { if (!s->is_state.incsearch_postponed) {
XFREE_CLEAR(s->prev_cmdbuff);
return 1; return 1;
} }
return command_line_changed(s); return command_line_changed(s);
@@ -2787,8 +2788,6 @@ static int command_line_changed(CommandLineState *s)
do_autocmd_cmdlinechanged(s->firstc > 0 ? s->firstc : '-'); do_autocmd_cmdlinechanged(s->firstc > 0 ? s->firstc : '-');
} }
XFREE_CLEAR(s->prev_cmdbuff);
may_trigger_cursormovedc(s); may_trigger_cursormovedc(s);
const bool prev_cmdpreview = cmdpreview; const bool prev_cmdpreview = cmdpreview;