mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 23:08:16 +00:00
memory: Add free
wrapper and refactor project to use it
We already use wrappers for allocation, the new `xfree` function is the equivalent for deallocation and provides a way to fully replace the malloc implementation used by Neovim.
This commit is contained in:
@@ -959,7 +959,7 @@ static void syn_stack_free_block(synblock_T *block)
|
||||
if (block->b_sst_array != NULL) {
|
||||
for (p = block->b_sst_first; p != NULL; p = p->sst_next)
|
||||
clear_syn_state(p);
|
||||
free(block->b_sst_array);
|
||||
xfree(block->b_sst_array);
|
||||
block->b_sst_array = NULL;
|
||||
block->b_sst_len = 0;
|
||||
}
|
||||
@@ -1044,7 +1044,7 @@ static void syn_stack_alloc(void)
|
||||
to->sst_next = to + 1;
|
||||
(sstp + len - 1)->sst_next = NULL;
|
||||
|
||||
free(syn_block->b_sst_array);
|
||||
xfree(syn_block->b_sst_array);
|
||||
syn_block->b_sst_array = sstp;
|
||||
syn_block->b_sst_len = len;
|
||||
}
|
||||
@@ -3054,7 +3054,7 @@ void syntax_clear(synblock_T *block)
|
||||
|
||||
vim_regfree(block->b_syn_linecont_prog);
|
||||
block->b_syn_linecont_prog = NULL;
|
||||
free(block->b_syn_linecont_pat);
|
||||
xfree(block->b_syn_linecont_pat);
|
||||
block->b_syn_linecont_pat = NULL;
|
||||
block->b_syn_folditems = 0;
|
||||
|
||||
@@ -3073,7 +3073,7 @@ void reset_synblock(win_T *wp)
|
||||
{
|
||||
if (wp->w_s != &wp->w_buffer->b_s) {
|
||||
syntax_clear(wp->w_s);
|
||||
free(wp->w_s);
|
||||
xfree(wp->w_s);
|
||||
wp->w_s = &wp->w_buffer->b_s;
|
||||
}
|
||||
}
|
||||
@@ -3097,7 +3097,7 @@ static void syntax_sync_clear(void)
|
||||
|
||||
vim_regfree(curwin->w_s->b_syn_linecont_prog);
|
||||
curwin->w_s->b_syn_linecont_prog = NULL;
|
||||
free(curwin->w_s->b_syn_linecont_pat);
|
||||
xfree(curwin->w_s->b_syn_linecont_pat);
|
||||
curwin->w_s->b_syn_linecont_pat = NULL;
|
||||
|
||||
syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */
|
||||
@@ -3125,13 +3125,13 @@ static void syn_remove_pattern(synblock_T *block, int idx)
|
||||
*/
|
||||
static void syn_clear_pattern(synblock_T *block, int i)
|
||||
{
|
||||
free(SYN_ITEMS(block)[i].sp_pattern);
|
||||
xfree(SYN_ITEMS(block)[i].sp_pattern);
|
||||
vim_regfree(SYN_ITEMS(block)[i].sp_prog);
|
||||
/* Only free sp_cont_list and sp_next_list of first start pattern */
|
||||
if (i == 0 || SYN_ITEMS(block)[i - 1].sp_type != SPTYPE_START) {
|
||||
free(SYN_ITEMS(block)[i].sp_cont_list);
|
||||
free(SYN_ITEMS(block)[i].sp_next_list);
|
||||
free(SYN_ITEMS(block)[i].sp_syn.cont_in_list);
|
||||
xfree(SYN_ITEMS(block)[i].sp_cont_list);
|
||||
xfree(SYN_ITEMS(block)[i].sp_next_list);
|
||||
xfree(SYN_ITEMS(block)[i].sp_syn.cont_in_list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3140,9 +3140,9 @@ static void syn_clear_pattern(synblock_T *block, int i)
|
||||
*/
|
||||
static void syn_clear_cluster(synblock_T *block, int i)
|
||||
{
|
||||
free(SYN_CLSTR(block)[i].scl_name);
|
||||
free(SYN_CLSTR(block)[i].scl_name_u);
|
||||
free(SYN_CLSTR(block)[i].scl_list);
|
||||
xfree(SYN_CLSTR(block)[i].scl_name);
|
||||
xfree(SYN_CLSTR(block)[i].scl_name_u);
|
||||
xfree(SYN_CLSTR(block)[i].scl_list);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3198,7 +3198,7 @@ static void syn_cmd_clear(exarg_T *eap, int syncing)
|
||||
*/
|
||||
short scl_id = id - SYNID_CLUSTER;
|
||||
|
||||
free(SYN_CLSTR(curwin->w_s)[scl_id].scl_list);
|
||||
xfree(SYN_CLSTR(curwin->w_s)[scl_id].scl_list);
|
||||
SYN_CLSTR(curwin->w_s)[scl_id].scl_list = NULL;
|
||||
}
|
||||
} else {
|
||||
@@ -3760,9 +3760,9 @@ static void syn_clear_keyword(int id, hashtab_T *ht)
|
||||
hi->hi_key = KE2HIKEY(kp_next);
|
||||
} else
|
||||
kp_prev->ke_next = kp_next;
|
||||
free(kp->next_list);
|
||||
free(kp->k_syn.cont_in_list);
|
||||
free(kp);
|
||||
xfree(kp->next_list);
|
||||
xfree(kp->k_syn.cont_in_list);
|
||||
xfree(kp);
|
||||
kp = kp_next;
|
||||
} else {
|
||||
kp_prev = kp;
|
||||
@@ -3789,9 +3789,9 @@ static void clear_keywtab(hashtab_T *ht)
|
||||
--todo;
|
||||
for (kp = HI2KE(hi); kp != NULL; kp = kp_next) {
|
||||
kp_next = kp->ke_next;
|
||||
free(kp->next_list);
|
||||
free(kp->k_syn.cont_in_list);
|
||||
free(kp);
|
||||
xfree(kp->next_list);
|
||||
xfree(kp->k_syn.cont_in_list);
|
||||
xfree(kp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4011,12 +4011,12 @@ get_syn_options (
|
||||
}
|
||||
if (i < 0) {
|
||||
EMSG2(_("E394: Didn't find region item for %s"), gname);
|
||||
free(gname);
|
||||
xfree(gname);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
free(gname);
|
||||
xfree(gname);
|
||||
arg = skipwhite(arg);
|
||||
} else if (flagtab[fidx].flags == HL_FOLD
|
||||
&& foldmethodIsSyntax(curwin))
|
||||
@@ -4208,9 +4208,9 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing)
|
||||
}
|
||||
}
|
||||
|
||||
free(keyword_copy);
|
||||
free(syn_opt_arg.cont_in_list);
|
||||
free(syn_opt_arg.next_list);
|
||||
xfree(keyword_copy);
|
||||
xfree(syn_opt_arg.cont_in_list);
|
||||
xfree(syn_opt_arg.next_list);
|
||||
}
|
||||
|
||||
if (rest != NULL)
|
||||
@@ -4311,10 +4311,10 @@ syn_cmd_match (
|
||||
* Something failed, free the allocated memory.
|
||||
*/
|
||||
vim_regfree(item.sp_prog);
|
||||
free(item.sp_pattern);
|
||||
free(syn_opt_arg.cont_list);
|
||||
free(syn_opt_arg.cont_in_list);
|
||||
free(syn_opt_arg.next_list);
|
||||
xfree(item.sp_pattern);
|
||||
xfree(syn_opt_arg.cont_list);
|
||||
xfree(syn_opt_arg.cont_in_list);
|
||||
xfree(syn_opt_arg.next_list);
|
||||
|
||||
if (rest == NULL)
|
||||
EMSG2(_(e_invarg2), arg);
|
||||
@@ -4388,7 +4388,7 @@ syn_cmd_region (
|
||||
key_end = rest;
|
||||
while (*key_end && !vim_iswhite(*key_end) && *key_end != '=')
|
||||
++key_end;
|
||||
free(key);
|
||||
xfree(key);
|
||||
key = vim_strnsave_up(rest, (int)(key_end - rest));
|
||||
if (STRCMP(key, "MATCHGROUP") == 0)
|
||||
item = ITEM_MATCHGROUP;
|
||||
@@ -4456,7 +4456,7 @@ syn_cmd_region (
|
||||
++pat_count;
|
||||
}
|
||||
}
|
||||
free(key);
|
||||
xfree(key);
|
||||
if (illegal || not_enough)
|
||||
rest = NULL;
|
||||
|
||||
@@ -4530,17 +4530,17 @@ syn_cmd_region (
|
||||
for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp_next) {
|
||||
if (!success) {
|
||||
vim_regfree(ppp->pp_synp->sp_prog);
|
||||
free(ppp->pp_synp->sp_pattern);
|
||||
xfree(ppp->pp_synp->sp_pattern);
|
||||
}
|
||||
free(ppp->pp_synp);
|
||||
xfree(ppp->pp_synp);
|
||||
ppp_next = ppp->pp_next;
|
||||
free(ppp);
|
||||
xfree(ppp);
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
free(syn_opt_arg.cont_list);
|
||||
free(syn_opt_arg.cont_in_list);
|
||||
free(syn_opt_arg.next_list);
|
||||
xfree(syn_opt_arg.cont_list);
|
||||
xfree(syn_opt_arg.cont_in_list);
|
||||
xfree(syn_opt_arg.next_list);
|
||||
if (not_enough)
|
||||
EMSG2(_("E399: Not enough arguments: syntax region %s"), arg);
|
||||
else if (illegal || rest == NULL)
|
||||
@@ -4580,11 +4580,11 @@ static void syn_combine_list(short **clstr1, short **clstr2, int list_op)
|
||||
return;
|
||||
if (*clstr1 == NULL || list_op == CLUSTER_REPLACE) {
|
||||
if (list_op == CLUSTER_REPLACE)
|
||||
free(*clstr1);
|
||||
xfree(*clstr1);
|
||||
if (list_op == CLUSTER_REPLACE || list_op == CLUSTER_ADD)
|
||||
*clstr1 = *clstr2;
|
||||
else
|
||||
free(*clstr2);
|
||||
xfree(*clstr2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4668,8 +4668,8 @@ static void syn_combine_list(short **clstr1, short **clstr2, int list_op)
|
||||
/*
|
||||
* Finally, put the new list in place.
|
||||
*/
|
||||
free(*clstr1);
|
||||
free(*clstr2);
|
||||
xfree(*clstr1);
|
||||
xfree(*clstr2);
|
||||
*clstr1 = clstr;
|
||||
}
|
||||
|
||||
@@ -4688,7 +4688,7 @@ static int syn_scl_name2id(char_u *name)
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(name_u);
|
||||
xfree(name_u);
|
||||
return i < 0 ? 0 : i + SYNID_CLUSTER;
|
||||
}
|
||||
|
||||
@@ -4699,7 +4699,7 @@ static int syn_scl_namen2id(char_u *linep, int len)
|
||||
{
|
||||
char_u *name = vim_strnsave(linep, len);
|
||||
int id = syn_scl_name2id(name);
|
||||
free(name);
|
||||
xfree(name);
|
||||
|
||||
return id;
|
||||
}
|
||||
@@ -4721,7 +4721,7 @@ static int syn_check_cluster(char_u *pp, int len)
|
||||
if (id == 0) /* doesn't exist yet */
|
||||
id = syn_add_cluster(name);
|
||||
else
|
||||
free(name);
|
||||
xfree(name);
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -4743,7 +4743,7 @@ static int syn_add_cluster(char_u *name)
|
||||
int len = curwin->w_s->b_syn_clusters.ga_len;
|
||||
if (len >= MAX_CLUSTER_ID) {
|
||||
EMSG((char_u *)_("E848: Too many syntax clusters"));
|
||||
free(name);
|
||||
xfree(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4945,7 +4945,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing)
|
||||
while (!ends_excmd(*arg_start)) {
|
||||
arg_end = skiptowhite(arg_start);
|
||||
next_arg = skipwhite(arg_end);
|
||||
free(key);
|
||||
xfree(key);
|
||||
key = vim_strnsave_up(arg_start, (int)(arg_end - arg_start));
|
||||
if (STRCMP(key, "CCOMMENT") == 0) {
|
||||
if (!eap->skip)
|
||||
@@ -5013,7 +5013,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing)
|
||||
syn_clear_time(&curwin->w_s->b_syn_linecont_time);
|
||||
|
||||
if (curwin->w_s->b_syn_linecont_prog == NULL) {
|
||||
free(curwin->w_s->b_syn_linecont_pat);
|
||||
xfree(curwin->w_s->b_syn_linecont_pat);
|
||||
curwin->w_s->b_syn_linecont_pat = NULL;
|
||||
finished = TRUE;
|
||||
break;
|
||||
@@ -5035,7 +5035,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing)
|
||||
}
|
||||
arg_start = next_arg;
|
||||
}
|
||||
free(key);
|
||||
xfree(key);
|
||||
if (illegal)
|
||||
EMSG2(_("E404: Illegal arguments: %s"), arg_start);
|
||||
else if (!finished) {
|
||||
@@ -5109,13 +5109,13 @@ get_id_list (
|
||||
if (TOUPPER_ASC(**arg) != 'C') {
|
||||
EMSG2(_("E407: %s not allowed here"), name + 1);
|
||||
failed = TRUE;
|
||||
free(name);
|
||||
xfree(name);
|
||||
break;
|
||||
}
|
||||
if (count != 0) {
|
||||
EMSG2(_("E408: %s must be first in contains list"), name + 1);
|
||||
failed = TRUE;
|
||||
free(name);
|
||||
xfree(name);
|
||||
break;
|
||||
}
|
||||
if (name[1] == 'A')
|
||||
@@ -5142,7 +5142,7 @@ get_id_list (
|
||||
regmatch.regprog = vim_regcomp(name, RE_MAGIC);
|
||||
if (regmatch.regprog == NULL) {
|
||||
failed = TRUE;
|
||||
free(name);
|
||||
xfree(name);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -5156,7 +5156,7 @@ get_id_list (
|
||||
* "contains=a.*b,axb".
|
||||
* Go back to first round */
|
||||
if (count >= total_count) {
|
||||
free(retval);
|
||||
xfree(retval);
|
||||
round = 1;
|
||||
} else
|
||||
retval[count] = i + 1;
|
||||
@@ -5168,7 +5168,7 @@ get_id_list (
|
||||
vim_regfree(regmatch.regprog);
|
||||
}
|
||||
}
|
||||
free(name);
|
||||
xfree(name);
|
||||
if (id == 0) {
|
||||
EMSG2(_("E409: Unknown group name: %s"), p);
|
||||
failed = TRUE;
|
||||
@@ -5178,7 +5178,7 @@ get_id_list (
|
||||
if (round == 2) {
|
||||
/* Got more items than expected, go back to first round */
|
||||
if (count >= total_count) {
|
||||
free(retval);
|
||||
xfree(retval);
|
||||
round = 1;
|
||||
} else
|
||||
retval[count] = id;
|
||||
@@ -5201,14 +5201,14 @@ get_id_list (
|
||||
|
||||
*arg = p;
|
||||
if (failed || retval == NULL) {
|
||||
free(retval);
|
||||
xfree(retval);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (*list == NULL)
|
||||
*list = retval;
|
||||
else
|
||||
free(retval); /* list already found, don't overwrite it */
|
||||
xfree(retval); /* list already found, don't overwrite it */
|
||||
|
||||
return OK;
|
||||
}
|
||||
@@ -5387,7 +5387,7 @@ void ex_syntax(exarg_T *eap)
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(subcmd_name);
|
||||
xfree(subcmd_name);
|
||||
if (eap->skip)
|
||||
--emsg_skip;
|
||||
}
|
||||
@@ -5427,7 +5427,7 @@ void ex_ownsyntax(exarg_T *eap)
|
||||
do_unlet((char_u *)"b:current_syntax", TRUE);
|
||||
else {
|
||||
set_internal_string_var((char_u *)"b:current_syntax", old_value);
|
||||
free(old_value);
|
||||
xfree(old_value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5862,7 +5862,7 @@ init_highlight (
|
||||
// p invalid, so copy it.
|
||||
char_u *copy_p = vim_strsave(p);
|
||||
bool okay = load_colors(copy_p);
|
||||
free(copy_p);
|
||||
xfree(copy_p);
|
||||
if (okay) {
|
||||
return;
|
||||
}
|
||||
@@ -5943,7 +5943,7 @@ int load_colors(char_u *name)
|
||||
buf = xmalloc(STRLEN(name) + 12);
|
||||
sprintf((char *)buf, "colors/%s.vim", name);
|
||||
retval = source_runtime(buf, FALSE);
|
||||
free(buf);
|
||||
xfree(buf);
|
||||
apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf);
|
||||
|
||||
recursive = FALSE;
|
||||
@@ -6145,7 +6145,7 @@ do_highlight (
|
||||
*/
|
||||
while (*linep && !vim_iswhite(*linep) && *linep != '=')
|
||||
++linep;
|
||||
free(key);
|
||||
xfree(key);
|
||||
key = vim_strnsave_up(key_start, (int)(linep - key_start));
|
||||
linep = skipwhite(linep);
|
||||
|
||||
@@ -6189,7 +6189,7 @@ do_highlight (
|
||||
error = TRUE;
|
||||
break;
|
||||
}
|
||||
free(arg);
|
||||
xfree(arg);
|
||||
arg = vim_strnsave(arg_start, (int)(linep - arg_start));
|
||||
|
||||
if (*linep == '\'')
|
||||
@@ -6394,7 +6394,7 @@ do_highlight (
|
||||
if (!init)
|
||||
HL_TABLE()[idx].sg_set |= SG_GUI;
|
||||
|
||||
free(HL_TABLE()[idx].sg_rgb_fg_name);
|
||||
xfree(HL_TABLE()[idx].sg_rgb_fg_name);
|
||||
if (STRCMP(arg, "NONE")) {
|
||||
HL_TABLE()[idx].sg_rgb_fg_name = (uint8_t *)xstrdup((char *)arg);
|
||||
HL_TABLE()[idx].sg_rgb_fg = name_to_color(arg);
|
||||
@@ -6412,7 +6412,7 @@ do_highlight (
|
||||
if (!init)
|
||||
HL_TABLE()[idx].sg_set |= SG_GUI;
|
||||
|
||||
free(HL_TABLE()[idx].sg_rgb_bg_name);
|
||||
xfree(HL_TABLE()[idx].sg_rgb_bg_name);
|
||||
if (STRCMP(arg, "NONE") != 0) {
|
||||
HL_TABLE()[idx].sg_rgb_bg_name = (uint8_t *)xstrdup((char *)arg);
|
||||
HL_TABLE()[idx].sg_rgb_bg = name_to_color(arg);
|
||||
@@ -6462,8 +6462,8 @@ do_highlight (
|
||||
HL_TABLE()[idx].sg_scriptID = current_SID;
|
||||
redraw_all_later(NOT_VALID);
|
||||
}
|
||||
free(key);
|
||||
free(arg);
|
||||
xfree(key);
|
||||
xfree(arg);
|
||||
|
||||
/* Only call highlight_changed() once, after sourcing a syntax file */
|
||||
need_highlight_changed = TRUE;
|
||||
@@ -6474,8 +6474,8 @@ void free_highlight(void)
|
||||
{
|
||||
for (int i = 0; i < highlight_ga.ga_len; ++i) {
|
||||
highlight_clear(i);
|
||||
free(HL_TABLE()[i].sg_name);
|
||||
free(HL_TABLE()[i].sg_name_u);
|
||||
xfree(HL_TABLE()[i].sg_name);
|
||||
xfree(HL_TABLE()[i].sg_name_u);
|
||||
}
|
||||
ga_clear(&highlight_ga);
|
||||
}
|
||||
@@ -6522,9 +6522,9 @@ static void highlight_clear(int idx)
|
||||
HL_TABLE()[idx].sg_gui = 0;
|
||||
HL_TABLE()[idx].sg_rgb_fg = -1;
|
||||
HL_TABLE()[idx].sg_rgb_bg = -1;
|
||||
free(HL_TABLE()[idx].sg_rgb_fg_name);
|
||||
xfree(HL_TABLE()[idx].sg_rgb_fg_name);
|
||||
HL_TABLE()[idx].sg_rgb_fg_name = NULL;
|
||||
free(HL_TABLE()[idx].sg_rgb_bg_name);
|
||||
xfree(HL_TABLE()[idx].sg_rgb_bg_name);
|
||||
HL_TABLE()[idx].sg_rgb_bg_name = NULL;
|
||||
/* Clear the script ID only when there is no link, since that is not
|
||||
* cleared. */
|
||||
@@ -6959,7 +6959,7 @@ int syn_namen2id(char_u *linep, int len)
|
||||
{
|
||||
char_u *name = vim_strnsave(linep, len);
|
||||
int id = syn_name2id(name);
|
||||
free(name);
|
||||
xfree(name);
|
||||
|
||||
return id;
|
||||
}
|
||||
@@ -6981,7 +6981,7 @@ int syn_check_group(char_u *pp, int len)
|
||||
if (id == 0) /* doesn't exist yet */
|
||||
id = syn_add_group(name);
|
||||
else
|
||||
free(name);
|
||||
xfree(name);
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -6998,7 +6998,7 @@ static int syn_add_group(char_u *name)
|
||||
for (p = name; *p != NUL; ++p) {
|
||||
if (!vim_isprintc(*p)) {
|
||||
EMSG(_("E669: Unprintable character in group name"));
|
||||
free(name);
|
||||
xfree(name);
|
||||
return 0;
|
||||
} else if (!ASCII_ISALNUM(*p) && *p != '_') {
|
||||
/* This is an error, but since there previously was no check only
|
||||
@@ -7019,7 +7019,7 @@ static int syn_add_group(char_u *name)
|
||||
|
||||
if (highlight_ga.ga_len >= MAX_HL_ID) {
|
||||
EMSG(_("E849: Too many highlight and syntax groups"));
|
||||
free(name);
|
||||
xfree(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -7039,8 +7039,8 @@ static int syn_add_group(char_u *name)
|
||||
static void syn_unadd_group(void)
|
||||
{
|
||||
--highlight_ga.ga_len;
|
||||
free(HL_TABLE()[highlight_ga.ga_len].sg_name);
|
||||
free(HL_TABLE()[highlight_ga.ga_len].sg_name_u);
|
||||
xfree(HL_TABLE()[highlight_ga.ga_len].sg_name);
|
||||
xfree(HL_TABLE()[highlight_ga.ga_len].sg_name_u);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user