vim-patch:9.1.1734: Memory leak when allocating match fails (#35646)

Problem:  Memory leak when allocating match fails
Solution: Initialize m to NULL and centralize cleanup via goto fail to
          avoid leaks on early returns (Damien Lejay)

closes: vim/vim#18204

37e7728294

Co-authored-by: Damien Lejay <damien@lejay.be>
This commit is contained in:
zeertzjq
2025-09-06 08:03:57 +08:00
committed by GitHub
parent 7175fe87dc
commit 51af2797c2

View File

@@ -46,7 +46,7 @@ static const char *e_invalwindow = N_("E957: Invalid window number");
/// Add match to the match list of window "wp".
/// If "pat" is not NULL the pattern will be highlighted with the group "grp"
/// with priority "prio".
/// If "pos_list" is not NULL the list of posisions defines the highlights.
/// If "pos_list" is not NULL the list of positions defines the highlights.
/// Optionally, a desired ID "id" can be specified (greater than or equal to 1).
/// If no particular ID is desired, -1 must be specified for "id".
///
@@ -214,6 +214,7 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in
return id;
fail:
vim_regfree(regprog);
xfree(m->mit_pattern);
xfree(m->mit_pos_array);
xfree(m);