mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 23:38:17 +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:
@@ -482,7 +482,7 @@ edit (
|
||||
new_insert_skip = 0;
|
||||
else {
|
||||
new_insert_skip = (int)STRLEN(ptr);
|
||||
free(ptr);
|
||||
xfree(ptr);
|
||||
}
|
||||
|
||||
old_indent = 0;
|
||||
@@ -652,7 +652,7 @@ edit (
|
||||
if (str != NULL) {
|
||||
for (p = str; *p != NUL; mb_ptr_adv(p))
|
||||
ins_compl_addleader(PTR2CHAR(p));
|
||||
free(str);
|
||||
xfree(str);
|
||||
} else
|
||||
ins_compl_addleader(c);
|
||||
continue;
|
||||
@@ -1153,7 +1153,7 @@ normalchar:
|
||||
}
|
||||
AppendToRedobuffLit(str, -1);
|
||||
}
|
||||
free(str);
|
||||
xfree(str);
|
||||
c = NUL;
|
||||
}
|
||||
|
||||
@@ -1569,7 +1569,7 @@ change_indent (
|
||||
memset(ptr, ' ', i);
|
||||
new_cursor_col += i;
|
||||
ins_str(ptr);
|
||||
free(ptr);
|
||||
xfree(ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1648,7 +1648,7 @@ change_indent (
|
||||
/* Insert new stuff into line again */
|
||||
ins_bytes(new_line);
|
||||
|
||||
free(new_line);
|
||||
xfree(new_line);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1970,7 +1970,7 @@ int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int
|
||||
*(p++) = wca[i++];
|
||||
*p = NUL;
|
||||
|
||||
free(wca);
|
||||
xfree(wca);
|
||||
|
||||
return ins_compl_add(IObuff, len, icase, fname, NULL, dir,
|
||||
flags, FALSE);
|
||||
@@ -2273,7 +2273,7 @@ static void ins_compl_del_pum(void)
|
||||
{
|
||||
if (compl_match_array != NULL) {
|
||||
pum_undisplay();
|
||||
free(compl_match_array);
|
||||
xfree(compl_match_array);
|
||||
compl_match_array = NULL;
|
||||
}
|
||||
}
|
||||
@@ -2490,8 +2490,8 @@ ins_compl_dictionaries (
|
||||
ptr = xmalloc(len);
|
||||
vim_snprintf((char *)ptr, len, "^\\s*\\zs\\V%s", pat_esc);
|
||||
regmatch.regprog = vim_regcomp(ptr, RE_MAGIC);
|
||||
free(pat_esc);
|
||||
free(ptr);
|
||||
xfree(pat_esc);
|
||||
xfree(ptr);
|
||||
} else {
|
||||
regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
|
||||
if (regmatch.regprog == NULL)
|
||||
@@ -2539,7 +2539,7 @@ ins_compl_dictionaries (
|
||||
theend:
|
||||
p_scs = save_p_scs;
|
||||
vim_regfree(regmatch.regprog);
|
||||
free(buf);
|
||||
xfree(buf);
|
||||
}
|
||||
|
||||
static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir)
|
||||
@@ -2689,9 +2689,9 @@ static void ins_compl_free(void)
|
||||
compl_T *match;
|
||||
int i;
|
||||
|
||||
free(compl_pattern);
|
||||
xfree(compl_pattern);
|
||||
compl_pattern = NULL;
|
||||
free(compl_leader);
|
||||
xfree(compl_leader);
|
||||
compl_leader = NULL;
|
||||
|
||||
if (compl_first_match == NULL)
|
||||
@@ -2704,13 +2704,13 @@ static void ins_compl_free(void)
|
||||
do {
|
||||
match = compl_curr_match;
|
||||
compl_curr_match = compl_curr_match->cp_next;
|
||||
free(match->cp_str);
|
||||
xfree(match->cp_str);
|
||||
/* several entries may use the same fname, free it just once. */
|
||||
if (match->cp_flags & FREE_FNAME)
|
||||
free(match->cp_fname);
|
||||
xfree(match->cp_fname);
|
||||
for (i = 0; i < CPT_COUNT; ++i)
|
||||
free(match->cp_text[i]);
|
||||
free(match);
|
||||
xfree(match->cp_text[i]);
|
||||
xfree(match);
|
||||
} while (compl_curr_match != NULL && compl_curr_match != compl_first_match);
|
||||
compl_first_match = compl_curr_match = NULL;
|
||||
compl_shown_match = NULL;
|
||||
@@ -2721,12 +2721,12 @@ static void ins_compl_clear(void)
|
||||
compl_cont_status = 0;
|
||||
compl_started = FALSE;
|
||||
compl_matches = 0;
|
||||
free(compl_pattern);
|
||||
xfree(compl_pattern);
|
||||
compl_pattern = NULL;
|
||||
free(compl_leader);
|
||||
xfree(compl_leader);
|
||||
compl_leader = NULL;
|
||||
edit_submode_extra = NULL;
|
||||
free(compl_orig_text);
|
||||
xfree(compl_orig_text);
|
||||
compl_orig_text = NULL;
|
||||
compl_enter_selects = FALSE;
|
||||
}
|
||||
@@ -2767,7 +2767,7 @@ static int ins_compl_bs(void)
|
||||
|| ins_compl_need_restart())
|
||||
ins_compl_restart();
|
||||
|
||||
free(compl_leader);
|
||||
xfree(compl_leader);
|
||||
compl_leader = vim_strnsave(line + compl_col, (int)(p - line) - compl_col);
|
||||
ins_compl_new_leader();
|
||||
if (compl_shown_match != NULL)
|
||||
@@ -2871,7 +2871,7 @@ static void ins_compl_addleader(int c)
|
||||
* cursor doesn't point original position, changing compl_leader would
|
||||
* break redo. */
|
||||
if (!compl_opt_refresh_always) {
|
||||
free(compl_leader);
|
||||
xfree(compl_leader);
|
||||
compl_leader = vim_strnsave(get_cursor_line_ptr() + compl_col,
|
||||
(int)(curwin->w_cursor.col - compl_col));
|
||||
ins_compl_new_leader();
|
||||
@@ -2898,7 +2898,7 @@ static void ins_compl_set_original_text(char_u *str)
|
||||
{
|
||||
/* Replace the original text entry. */
|
||||
if (compl_first_match->cp_flags & ORIGINAL_TEXT) { /* safety check */
|
||||
free(compl_first_match->cp_str);
|
||||
xfree(compl_first_match->cp_str);
|
||||
compl_first_match->cp_str = vim_strsave(str);
|
||||
}
|
||||
}
|
||||
@@ -4449,13 +4449,13 @@ static int ins_complete(int c)
|
||||
ins_compl_fixRedoBufForLeader(NULL);
|
||||
|
||||
/* Always add completion for the original text. */
|
||||
free(compl_orig_text);
|
||||
xfree(compl_orig_text);
|
||||
compl_orig_text = vim_strnsave(line + compl_col, compl_length);
|
||||
if (ins_compl_add(compl_orig_text, -1, p_ic, NULL, NULL, 0,
|
||||
ORIGINAL_TEXT, FALSE) != OK) {
|
||||
free(compl_pattern);
|
||||
xfree(compl_pattern);
|
||||
compl_pattern = NULL;
|
||||
free(compl_orig_text);
|
||||
xfree(compl_orig_text);
|
||||
compl_orig_text = NULL;
|
||||
return FAIL;
|
||||
}
|
||||
@@ -5326,7 +5326,7 @@ internal_format (
|
||||
* moved, now we re-insert it into the new line.
|
||||
*/
|
||||
ins_bytes(saved_text);
|
||||
free(saved_text);
|
||||
xfree(saved_text);
|
||||
} else {
|
||||
/*
|
||||
* Check if cursor is not past the NUL off the line, cindent
|
||||
@@ -5661,11 +5661,11 @@ stop_insert (
|
||||
ptr = get_inserted();
|
||||
if (did_restart_edit == 0 || (ptr != NULL
|
||||
&& (int)STRLEN(ptr) > new_insert_skip)) {
|
||||
free(last_insert);
|
||||
xfree(last_insert);
|
||||
last_insert = ptr;
|
||||
last_insert_skip = new_insert_skip;
|
||||
} else
|
||||
free(ptr);
|
||||
xfree(ptr);
|
||||
|
||||
if (!arrow_used && end_insert_pos != NULL) {
|
||||
/* Auto-format now. It may seem strange to do this when stopping an
|
||||
@@ -5770,7 +5770,7 @@ void set_last_insert(int c)
|
||||
{
|
||||
char_u *s;
|
||||
|
||||
free(last_insert);
|
||||
xfree(last_insert);
|
||||
last_insert = xmalloc(MB_MAXBYTES * 3 + 5);
|
||||
s = last_insert;
|
||||
/* Use the CTRL-V only when entering a special char */
|
||||
@@ -5785,9 +5785,9 @@ void set_last_insert(int c)
|
||||
#if defined(EXITFREE)
|
||||
void free_last_insert(void)
|
||||
{
|
||||
free(last_insert);
|
||||
xfree(last_insert);
|
||||
last_insert = NULL;
|
||||
free(compl_orig_text);
|
||||
xfree(compl_orig_text);
|
||||
compl_orig_text = NULL;
|
||||
}
|
||||
|
||||
@@ -6307,7 +6307,7 @@ static void mb_replace_pop_ins(int cc)
|
||||
*/
|
||||
static void replace_flush(void)
|
||||
{
|
||||
free(replace_stack);
|
||||
xfree(replace_stack);
|
||||
replace_stack = NULL;
|
||||
replace_stack_len = 0;
|
||||
replace_stack_nr = 0;
|
||||
@@ -7966,7 +7966,7 @@ static int ins_tab(void)
|
||||
}
|
||||
|
||||
if (State & VREPLACE_FLAG)
|
||||
free(saved_line);
|
||||
xfree(saved_line);
|
||||
curwin->w_p_list = save_list;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user