* 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".
* Return ID of added match, -1 on failure.
{
matchitem_T *cur;
matchitem_T *prev;
- matchitem_T *m;
+ matchitem_T *m = NULL;
int hlg_id;
regprog_T *regprog = NULL;
int rtype = UPD_SOME_VALID;
// Build new match.
m = ALLOC_CLEAR_ONE(matchitem_T);
if (m == NULL)
- return -1;
+ goto fail;
if (pos_list != NULL && pos_list->lv_len > 0)
{
m->mit_pos_array = ALLOC_CLEAR_MULT(llpos_T, pos_list->lv_len);
if (m->mit_pos_array == NULL)
- {
- vim_free(m);
- return -1;
- }
+ goto fail;
m->mit_pos_count = pos_list->lv_len;
}
m->mit_id = id;
return id;
fail:
- vim_free(m->mit_pattern);
- vim_free(m->mit_pos_array);
- vim_free(m);
+ vim_regfree(regprog);
+ if (m != NULL)
+ {
+ vim_free(m->mit_pattern);
+ vim_free(m->mit_pos_array);
+ vim_free(m);
+ }
return -1;
}