mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 08:18: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:
@@ -131,7 +131,7 @@ int setmark_pos(int c, pos_T *pos, int fnum)
|
||||
i = c - 'A';
|
||||
namedfm[i].fmark.mark = *pos;
|
||||
namedfm[i].fmark.fnum = fnum;
|
||||
free(namedfm[i].fname);
|
||||
xfree(namedfm[i].fname);
|
||||
namedfm[i].fname = NULL;
|
||||
return OK;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ void setpcmark(void)
|
||||
/* If jumplist is full: remove oldest entry */
|
||||
if (++curwin->w_jumplistlen > JUMPLISTSIZE) {
|
||||
curwin->w_jumplistlen = JUMPLISTSIZE;
|
||||
free(curwin->w_jumplist[0].fname);
|
||||
xfree(curwin->w_jumplist[0].fname);
|
||||
for (i = 1; i < JUMPLISTSIZE; ++i)
|
||||
curwin->w_jumplist[i - 1] = curwin->w_jumplist[i];
|
||||
}
|
||||
@@ -496,7 +496,7 @@ void fmarks_check_names(buf_T *buf)
|
||||
}
|
||||
}
|
||||
|
||||
free(name);
|
||||
xfree(name);
|
||||
}
|
||||
|
||||
static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf)
|
||||
@@ -505,7 +505,7 @@ static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf)
|
||||
&& fm->fname != NULL
|
||||
&& fnamecmp(name, fm->fname) == 0) {
|
||||
fm->fmark.fnum = buf->b_fnum;
|
||||
free(fm->fname);
|
||||
xfree(fm->fname);
|
||||
fm->fname = NULL;
|
||||
}
|
||||
}
|
||||
@@ -623,7 +623,7 @@ void do_marks(exarg_T *eap)
|
||||
arg, &namedfm[i].fmark.mark, name,
|
||||
namedfm[i].fmark.fnum == curbuf->b_fnum);
|
||||
if (namedfm[i].fmark.fnum != 0)
|
||||
free(name);
|
||||
xfree(name);
|
||||
}
|
||||
}
|
||||
show_one_mark('"', arg, &curbuf->b_last_cursor, NULL, TRUE);
|
||||
@@ -678,7 +678,7 @@ show_one_mark (
|
||||
if (name != NULL) {
|
||||
msg_outtrans_attr(name, current ? hl_attr(HLF_D) : 0);
|
||||
if (mustfree)
|
||||
free(name);
|
||||
xfree(name);
|
||||
}
|
||||
}
|
||||
ui_flush(); /* show one line at a time */
|
||||
@@ -735,7 +735,7 @@ void ex_delmarks(exarg_T *eap)
|
||||
else
|
||||
n = i - 'A';
|
||||
namedfm[n].fmark.mark.lnum = 0;
|
||||
free(namedfm[n].fname);
|
||||
xfree(namedfm[n].fname);
|
||||
namedfm[n].fname = NULL;
|
||||
}
|
||||
}
|
||||
@@ -777,7 +777,7 @@ void ex_jumps(exarg_T *eap)
|
||||
|
||||
msg_putchar('\n');
|
||||
if (got_int) {
|
||||
free(name);
|
||||
xfree(name);
|
||||
break;
|
||||
}
|
||||
sprintf((char *)IObuff, "%c %2d %5ld %4d ",
|
||||
@@ -790,7 +790,7 @@ void ex_jumps(exarg_T *eap)
|
||||
msg_outtrans_attr(name,
|
||||
curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum
|
||||
? hl_attr(HLF_D) : 0);
|
||||
free(name);
|
||||
xfree(name);
|
||||
os_breakcheck();
|
||||
}
|
||||
ui_flush();
|
||||
@@ -824,7 +824,7 @@ void ex_changes(exarg_T *eap)
|
||||
msg_outtrans(IObuff);
|
||||
name = mark_line(&curbuf->b_changelist[i], 17);
|
||||
msg_outtrans_attr(name, hl_attr(HLF_D));
|
||||
free(name);
|
||||
xfree(name);
|
||||
os_breakcheck();
|
||||
}
|
||||
ui_flush();
|
||||
@@ -1120,7 +1120,7 @@ static void cleanup_jumplist(void)
|
||||
if (i >= curwin->w_jumplistlen) /* no duplicate */
|
||||
curwin->w_jumplist[to++] = curwin->w_jumplist[from];
|
||||
else
|
||||
free(curwin->w_jumplist[from].fname);
|
||||
xfree(curwin->w_jumplist[from].fname);
|
||||
}
|
||||
if (curwin->w_jumplistidx == curwin->w_jumplistlen)
|
||||
curwin->w_jumplistidx = to;
|
||||
@@ -1151,7 +1151,7 @@ void free_jumplist(win_T *wp)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < wp->w_jumplistlen; ++i)
|
||||
free(wp->w_jumplist[i].fname);
|
||||
xfree(wp->w_jumplist[i].fname);
|
||||
}
|
||||
|
||||
void set_last_cursor(win_T *win)
|
||||
@@ -1167,7 +1167,7 @@ void free_all_marks(void)
|
||||
|
||||
for (i = 0; i < NMARKS + EXTRA_MARKS; i++)
|
||||
if (namedfm[i].fmark.mark.lnum != 0)
|
||||
free(namedfm[i].fname);
|
||||
xfree(namedfm[i].fname);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1212,7 +1212,7 @@ int read_viminfo_filemark(vir_T *virp, int force)
|
||||
fm->fmark.mark.coladd = 0;
|
||||
fm->fmark.fnum = 0;
|
||||
str = skipwhite(str);
|
||||
free(fm->fname);
|
||||
xfree(fm->fname);
|
||||
fm->fname = viminfo_readstring(virp, (int)(str - virp->vir_line),
|
||||
FALSE);
|
||||
}
|
||||
@@ -1247,9 +1247,9 @@ void write_viminfo_filemarks(FILE *fp)
|
||||
: (name != NULL
|
||||
&& STRCMP(name, namedfm[i].fname) == 0)))
|
||||
break;
|
||||
free(name);
|
||||
xfree(name);
|
||||
|
||||
free(namedfm[i].fname);
|
||||
xfree(namedfm[i].fname);
|
||||
for (; i > NMARKS; --i)
|
||||
namedfm[i] = namedfm[i - 1];
|
||||
namedfm[NMARKS].fmark.mark = curwin->w_cursor;
|
||||
@@ -1293,7 +1293,7 @@ static void write_one_filemark(FILE *fp, xfmark_T *fm, int c1, int c2)
|
||||
}
|
||||
|
||||
if (fm->fmark.fnum != 0)
|
||||
free(name);
|
||||
xfree(name);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1317,7 +1317,7 @@ int removable(char_u *name)
|
||||
}
|
||||
}
|
||||
}
|
||||
free(name);
|
||||
xfree(name);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -1474,7 +1474,7 @@ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags
|
||||
count++;
|
||||
}
|
||||
}
|
||||
free(str);
|
||||
xfree(str);
|
||||
|
||||
pos.coladd = 0;
|
||||
while (!(eof = viminfo_readline(virp)) && line[0] == TAB) {
|
||||
@@ -1520,5 +1520,5 @@ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(name_buf);
|
||||
xfree(name_buf);
|
||||
}
|
||||
|
Reference in New Issue
Block a user