[vim/vim] Fix: memory leak in `change_indent` in `src/indent.c` (PR #19820)

1 view
Skip to first unread message

Huihui Huang

unread,
Mar 25, 2026, 8:08:23 AM (23 hours ago) Mar 25
to vim/vim, Subscribed

Problem

In change_indent() located in src/indent.c, when in VREPLACE mode, orig_line is allocated at line 1336 via vim_strnsave() to save the original line content:

if (State & VREPLACE_FLAG)
{
    orig_line = vim_strnsave(ml_get_curline(), ml_get_curline_len());
    orig_col = curwin->w_cursor.col;
}

Later, at line 1514, new_line is allocated. If that allocation fails, the function returns immediately without freeing orig_line:

new_line = vim_strnsave(ml_get_curline(), ml_get_curline_len());
if (new_line == NULL)
    return;       // orig_line is leaked

On the success path, orig_line is passed to ml_replace() with copy=FALSE, which consumes it (transfers ownership to the memline). But on this failure path, ownership was never transferred, so orig_line leaks.

Solution

Free orig_line before returning when new_line allocation fails. The fix is included in the commit.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/19820

Commit Summary

  • 56e260b Fix: memory leak in change_indent in src/indent.c

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19820@github.com>

Christian Brabandt

unread,
Mar 25, 2026, 3:19:00 PM (15 hours ago) Mar 25
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#19820)

thanks, makes sense.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19820/c4129133831@github.com>

Christian Brabandt

unread,
Mar 25, 2026, 3:22:07 PM (15 hours ago) Mar 25
to vim/vim, Subscribed

Closed #19820 via 0effd2f.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19820/issue_event/23904371447@github.com>

Reply all
Reply to author
Forward
0 new messages