mirror of
https://github.com/vim/vim.git
synced 2025-10-21 08:24:06 -04:00
patch 9.1.1734: Memory leak when allocating match fails
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: #18204 Signed-off-by: Damien Lejay <damien@lejay.be> Signed-off-by: Hirohito Higashi <h.east.727@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
4daf031253
commit
37e7728294
21
src/match.c
21
src/match.c
@@ -21,7 +21,7 @@
|
|||||||
* Add match to the match list of window "wp".
|
* Add match to the match list of window "wp".
|
||||||
* If "pat" is not NULL the pattern will be highlighted with the group "grp"
|
* If "pat" is not NULL the pattern will be highlighted with the group "grp"
|
||||||
* with priority "prio".
|
* 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).
|
* 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".
|
* If no particular ID is desired, -1 must be specified for "id".
|
||||||
* Return ID of added match, -1 on failure.
|
* Return ID of added match, -1 on failure.
|
||||||
@@ -38,7 +38,7 @@ match_add(
|
|||||||
{
|
{
|
||||||
matchitem_T *cur;
|
matchitem_T *cur;
|
||||||
matchitem_T *prev;
|
matchitem_T *prev;
|
||||||
matchitem_T *m;
|
matchitem_T *m = NULL;
|
||||||
int hlg_id;
|
int hlg_id;
|
||||||
regprog_T *regprog = NULL;
|
regprog_T *regprog = NULL;
|
||||||
int rtype = UPD_SOME_VALID;
|
int rtype = UPD_SOME_VALID;
|
||||||
@@ -86,15 +86,12 @@ match_add(
|
|||||||
// Build new match.
|
// Build new match.
|
||||||
m = ALLOC_CLEAR_ONE(matchitem_T);
|
m = ALLOC_CLEAR_ONE(matchitem_T);
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return -1;
|
goto fail;
|
||||||
if (pos_list != NULL && pos_list->lv_len > 0)
|
if (pos_list != NULL && pos_list->lv_len > 0)
|
||||||
{
|
{
|
||||||
m->mit_pos_array = ALLOC_CLEAR_MULT(llpos_T, pos_list->lv_len);
|
m->mit_pos_array = ALLOC_CLEAR_MULT(llpos_T, pos_list->lv_len);
|
||||||
if (m->mit_pos_array == NULL)
|
if (m->mit_pos_array == NULL)
|
||||||
{
|
goto fail;
|
||||||
vim_free(m);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
m->mit_pos_count = pos_list->lv_len;
|
m->mit_pos_count = pos_list->lv_len;
|
||||||
}
|
}
|
||||||
m->mit_id = id;
|
m->mit_id = id;
|
||||||
@@ -213,9 +210,13 @@ match_add(
|
|||||||
return id;
|
return id;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
vim_free(m->mit_pattern);
|
vim_regfree(regprog);
|
||||||
vim_free(m->mit_pos_array);
|
if (m != NULL)
|
||||||
vim_free(m);
|
{
|
||||||
|
vim_free(m->mit_pattern);
|
||||||
|
vim_free(m->mit_pos_array);
|
||||||
|
vim_free(m);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -724,6 +724,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1734,
|
||||||
/**/
|
/**/
|
||||||
1733,
|
1733,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user