Remove ckfree, and replace all references with free. Remove freefunc,

which is also equivilent to free. Remove some if(x)free(x)
redundancies.
This commit is contained in:
Aaron Lehmann 2002-08-02 06:39:47 +00:00
parent e85dbfdd80
commit 49c024addd

View File

@ -308,7 +308,6 @@ static int stacknleft = MINSIZE;
#define STADJUST(amount, p) (p += (amount), sstrnleft -= (amount)) #define STADJUST(amount, p) (p += (amount), sstrnleft -= (amount))
#define grabstackstr(p) stalloc(stackblocksize() - sstrnleft) #define grabstackstr(p) stalloc(stackblocksize() - sstrnleft)
#define ckfree(p) free((pointer)(p))
#ifdef DEBUG #ifdef DEBUG
@ -1305,7 +1304,7 @@ setalias(char *name, char *val)
INTOFF; INTOFF;
if (ap) { if (ap) {
if (!(ap->flag & ALIASINUSE)) { if (!(ap->flag & ALIASINUSE)) {
ckfree(ap->val); free(ap->val);
} }
ap->val = xstrdup(val); ap->val = xstrdup(val);
ap->flag &= ~ALIASDEAD; ap->flag &= ~ALIASDEAD;
@ -1446,9 +1445,9 @@ freealias(struct alias *ap)
} }
next = ap->next; next = ap->next;
ckfree(ap->name); free(ap->name);
ckfree(ap->val); free(ap->val);
ckfree(ap); free(ap);
return next; return next;
} }
@ -2171,18 +2170,6 @@ copyfunc(union node *n)
return copynode(n); return copynode(n);
} }
/*
* Free a parse tree.
*/
static void
freefunc(union node *n)
{
if (n)
ckfree(n);
}
/* /*
* Add a new command entry, replacing any existing command entry for * Add a new command entry, replacing any existing command entry for
* the same name. * the same name.
@ -2196,7 +2183,7 @@ addcmdentry(char *name, struct cmdentry *entry)
INTOFF; INTOFF;
cmdp = cmdlookup(name, 1); cmdp = cmdlookup(name, 1);
if (cmdp->cmdtype == CMDFUNCTION) { if (cmdp->cmdtype == CMDFUNCTION) {
freefunc(cmdp->param.func); free(cmdp->param.func);
} }
cmdp->cmdtype = entry->cmdtype; cmdp->cmdtype = entry->cmdtype;
cmdp->param = entry->u; cmdp->param = entry->u;
@ -3130,7 +3117,7 @@ clear_traps(void)
for (tp = trap ; tp < &trap[NSIG] ; tp++) { for (tp = trap ; tp < &trap[NSIG] ; tp++) {
if (*tp && **tp) { /* trap not NULL or SIG_IGN */ if (*tp && **tp) { /* trap not NULL or SIG_IGN */
INTOFF; INTOFF;
ckfree(*tp); free(*tp);
*tp = NULL; *tp = NULL;
if (tp != &trap[0]) if (tp != &trap[0])
setsignal(tp - trap); setsignal(tp - trap);
@ -3250,12 +3237,11 @@ popfile(void)
INTOFF; INTOFF;
if (pf->fd >= 0) if (pf->fd >= 0)
close(pf->fd); close(pf->fd);
if (pf->buf) free(pf->buf);
ckfree(pf->buf);
while (pf->strpush) while (pf->strpush)
popstring(); popstring();
parsefile = pf->prev; parsefile = pf->prev;
ckfree(pf); free(pf);
parsenleft = parsefile->nleft; parsenleft = parsefile->nleft;
parselleft = parsefile->lleft; parselleft = parsefile->lleft;
parsenextc = parsefile->nextc; parsenextc = parsefile->nextc;
@ -3543,7 +3529,7 @@ printentry(struct tblentry *cmdp, int verbose)
out1str("a function\n"); out1str("a function\n");
name = commandtext(cmdp->param.func); name = commandtext(cmdp->param.func);
printf("%s() {\n %s\n}", cmdp->cmdname, name); printf("%s() {\n %s\n}", cmdp->cmdname, name);
ckfree(name); free(name);
INTON; INTON;
} }
#ifdef DEBUG #ifdef DEBUG
@ -3867,7 +3853,7 @@ clearcmdentry(int firstchange)
|| (cmdp->cmdtype == CMDBUILTIN && || (cmdp->cmdtype == CMDBUILTIN &&
builtinloc >= firstchange)) { builtinloc >= firstchange)) {
*pp = cmdp->next; *pp = cmdp->next;
ckfree(cmdp); free(cmdp);
} else { } else {
pp = &cmdp->next; pp = &cmdp->next;
} }
@ -3894,8 +3880,8 @@ deletefuncs(void)
while ((cmdp = *pp) != NULL) { while ((cmdp = *pp) != NULL) {
if (cmdp->cmdtype == CMDFUNCTION) { if (cmdp->cmdtype == CMDFUNCTION) {
*pp = cmdp->next; *pp = cmdp->next;
freefunc(cmdp->param.func); free(cmdp->param.func);
ckfree(cmdp); free(cmdp);
} else { } else {
pp = &cmdp->next; pp = &cmdp->next;
} }
@ -3961,7 +3947,7 @@ delete_cmd_entry()
INTOFF; INTOFF;
cmdp = *lastcmdentry; cmdp = *lastcmdentry;
*lastcmdentry = cmdp->next; *lastcmdentry = cmdp->next;
ckfree(cmdp); free(cmdp);
INTON; INTON;
} }
@ -4010,7 +3996,7 @@ unsetfunc(char *name)
struct tblentry *cmdp; struct tblentry *cmdp;
if ((cmdp = cmdlookup(name, 0)) != NULL && cmdp->cmdtype == CMDFUNCTION) { if ((cmdp = cmdlookup(name, 0)) != NULL && cmdp->cmdtype == CMDFUNCTION) {
freefunc(cmdp->param.func); free(cmdp->param.func);
delete_cmd_entry(); delete_cmd_entry();
} }
} }
@ -4526,7 +4512,7 @@ removerecordregions(int endoff)
struct ifsregion *ifsp; struct ifsregion *ifsp;
INTOFF; INTOFF;
ifsp = ifsfirst.next->next; ifsp = ifsfirst.next->next;
ckfree(ifsfirst.next); free(ifsfirst.next);
ifsfirst.next = ifsp; ifsfirst.next = ifsp;
INTON; INTON;
} }
@ -4546,7 +4532,7 @@ removerecordregions(int endoff)
struct ifsregion *ifsp; struct ifsregion *ifsp;
INTOFF; INTOFF;
ifsp = ifslastp->next->next; ifsp = ifslastp->next->next;
ckfree(ifslastp->next); free(ifslastp->next);
ifslastp->next = ifsp; ifslastp->next = ifsp;
INTON; INTON;
} }
@ -4709,8 +4695,7 @@ err1:
err2: err2:
if (in.fd >= 0) if (in.fd >= 0)
close(in.fd); close(in.fd);
if (in.buf) free(in.buf);
ckfree(in.buf);
if (in.jp) if (in.jp)
exitstatus = waitforjob(in.jp); exitstatus = waitforjob(in.jp);
handler = savehandler; handler = savehandler;
@ -5091,7 +5076,7 @@ ifsfree(void)
struct ifsregion *ifsp; struct ifsregion *ifsp;
INTOFF; INTOFF;
ifsp = ifsfirst.next->next; ifsp = ifsfirst.next->next;
ckfree(ifsfirst.next); free(ifsfirst.next);
ifsfirst.next = ifsp; ifsfirst.next = ifsp;
INTON; INTON;
} }
@ -5203,7 +5188,7 @@ expandmeta(struct strlist *str, int flag)
} }
expmeta(expdir, str->text); expmeta(expdir, str->text);
ckfree(expdir); free(expdir);
expdir = NULL; expdir = NULL;
INTON; INTON;
if (exparg.lastp == savelastp) { if (exparg.lastp == savelastp) {
@ -5896,7 +5881,7 @@ popstring(void)
} }
} }
if (sp->string != sp->ap->val) { if (sp->string != sp->ap->val) {
ckfree(sp->string); free(sp->string);
} }
sp->ap->flag &= ~ALIASINUSE; sp->ap->flag &= ~ALIASINUSE;
@ -5910,7 +5895,7 @@ popstring(void)
/*dprintf("*** calling popstring: restoring to '%s'\n", parsenextc);*/ /*dprintf("*** calling popstring: restoring to '%s'\n", parsenextc);*/
parsefile->strpush = sp->prev; parsefile->strpush = sp->prev;
if (sp != &(parsefile->basestrpush)) if (sp != &(parsefile->basestrpush))
ckfree(sp); free(sp);
INTON; INTON;
} }
@ -6411,10 +6396,10 @@ freejob(struct job *jp)
INTOFF; INTOFF;
for (i = jp->nprocs, ps = jp->ps ; --i >= 0 ; ps++) { for (i = jp->nprocs, ps = jp->ps ; --i >= 0 ; ps++) {
if (ps->cmd != nullstr) if (ps->cmd != nullstr)
ckfree(ps->cmd); free(ps->cmd);
} }
if (jp->ps != &jp->ps0) if (jp->ps != &jp->ps0)
ckfree(jp->ps); free(jp->ps);
jp->used = 0; jp->used = 0;
#ifdef CONFIG_ASH_JOB_CONTROL #ifdef CONFIG_ASH_JOB_CONTROL
if (curjob == jp - jobtab + 1) if (curjob == jp - jobtab + 1)
@ -6555,7 +6540,7 @@ makejob(const union node *node, int nprocs)
for (i = 0; i < njobs; i++) for (i = 0; i < njobs; i++)
if (jp[i].ps == &jobtab[i].ps0) if (jp[i].ps == &jobtab[i].ps0)
jp[i].ps = &jp[i].ps0; jp[i].ps = &jp[i].ps0;
ckfree(jobtab); free(jobtab);
jobtab = jp; jobtab = jp;
} }
jp = jobtab + njobs; jp = jobtab + njobs;
@ -7368,7 +7353,6 @@ commandtext(const union node *n)
static void waitonint(int sig) { static void waitonint(int sig) {
intreceived = 1; intreceived = 1;
return;
} }
#ifdef CONFIG_ASH_MAIL #ifdef CONFIG_ASH_MAIL
@ -7840,7 +7824,7 @@ popstackmark(struct stackmark *mark)
while (stackp != mark->stackp) { while (stackp != mark->stackp) {
sp = stackp; sp = stackp;
stackp = sp->prev; stackp = sp->prev;
ckfree(sp); free(sp);
} }
stacknxt = mark->stacknxt; stacknxt = mark->stacknxt;
stacknleft = mark->stacknleft; stacknleft = mark->stacknleft;
@ -9025,8 +9009,8 @@ freeparam(volatile struct shparam *param)
if (param->malloc) { if (param->malloc) {
for (ap = param->p ; *ap ; ap++) for (ap = param->p ; *ap ; ap++)
ckfree(*ap); free(*ap);
ckfree(param->p); free(param->p);
} }
} }
@ -9051,7 +9035,7 @@ shiftcmd(int argc, char **argv)
shellparam.nparam -= n; shellparam.nparam -= n;
for (ap1 = shellparam.p ; --n >= 0 ; ap1++) { for (ap1 = shellparam.p ; --n >= 0 ; ap1++) {
if (shellparam.malloc) if (shellparam.malloc)
ckfree(*ap1); free(*ap1);
} }
ap2 = shellparam.p; ap2 = shellparam.p;
while ((*ap2++ = *ap1++) != NULL); while ((*ap2++ = *ap1++) != NULL);
@ -10673,8 +10657,7 @@ parsebackq: {
savepbq = parsebackquote; savepbq = parsebackquote;
if (setjmp(jmploc.loc)) { if (setjmp(jmploc.loc)) {
if (str) free(str);
ckfree(str);
parsebackquote = 0; parsebackquote = 0;
handler = savehandler; handler = savehandler;
longjmp(handler->loc, 1); longjmp(handler->loc, 1);
@ -10794,7 +10777,7 @@ done:
memcpy(out, str, savelen); memcpy(out, str, savelen);
STADJUST(savelen, out); STADJUST(savelen, out);
INTOFF; INTOFF;
ckfree(str); free(str);
str = NULL; str = NULL;
INTON; INTON;
} }
@ -11237,7 +11220,7 @@ popredir(void)
} }
} }
redirlist = rp->next; redirlist = rp->next;
ckfree(rp); free(rp);
INTON; INTON;
} }
@ -11683,8 +11666,7 @@ trapcmd(int argc, char **argv)
else else
action = xstrdup(action); action = xstrdup(action);
} }
if (trap[signo]) free(trap[signo]);
ckfree(trap[signo]);
trap[signo] = action; trap[signo] = action;
if (signo != 0) if (signo != 0)
setsignal(signo); setsignal(signo);
@ -11995,7 +11977,7 @@ setvareq(char *s, int flags)
(*vp->func)(strchr(s, '=') + 1); (*vp->func)(strchr(s, '=') + 1);
if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0) if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0)
ckfree(vp->text); free(vp->text);
vp->flags &= ~(VTEXTFIXED|VSTACK|VUNSET); vp->flags &= ~(VTEXTFIXED|VSTACK|VUNSET);
vp->flags |= flags; vp->flags |= flags;
@ -12122,9 +12104,9 @@ shprocvar(void) {
if ((vp->flags & VEXPORT) == 0) { if ((vp->flags & VEXPORT) == 0) {
*prev = vp->next; *prev = vp->next;
if ((vp->flags & VTEXTFIXED) == 0) if ((vp->flags & VTEXTFIXED) == 0)
ckfree(vp->text); free(vp->text);
if ((vp->flags & VSTRFIXED) == 0) if ((vp->flags & VSTRFIXED) == 0)
ckfree(vp); free(vp);
} else { } else {
if (vp->flags & VSTACK) { if (vp->flags & VSTACK) {
vp->text = xstrdup(vp->text); vp->text = xstrdup(vp->text);
@ -12270,16 +12252,16 @@ poplocalvars() {
vp = lvp->vp; vp = lvp->vp;
if (vp == NULL) { /* $- saved */ if (vp == NULL) { /* $- saved */
memcpy(optet_vals, lvp->text, sizeof optet_vals); memcpy(optet_vals, lvp->text, sizeof optet_vals);
ckfree(lvp->text); free(lvp->text);
} else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) { } else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) {
(void)unsetvar(vp->text); (void)unsetvar(vp->text);
} else { } else {
if ((vp->flags & VTEXTFIXED) == 0) if ((vp->flags & VTEXTFIXED) == 0)
ckfree(vp->text); free(vp->text);
vp->flags = lvp->flags; vp->flags = lvp->flags;
vp->text = lvp->text; vp->text = lvp->text;
} }
ckfree(lvp); free(lvp);
} }
} }
@ -12353,9 +12335,9 @@ unsetvar(const char *s)
vp->flags |= VUNSET; vp->flags |= VUNSET;
if ((vp->flags & VSTRFIXED) == 0) { if ((vp->flags & VSTRFIXED) == 0) {
if ((vp->flags & VTEXTFIXED) == 0) if ((vp->flags & VTEXTFIXED) == 0)
ckfree(vp->text); free(vp->text);
*vpp = vp->next; *vpp = vp->next;
ckfree(vp); free(vp);
} }
INTON; INTON;
return (0); return (0);
@ -12440,7 +12422,7 @@ findvar(struct var **vpp, const char *name)
/* /*
* Copyright (c) 1999 Herbert Xu <herbert@debian.org> * Copyright (c) 1999 Herbert Xu <herbert@debian.org>
* This file contains code for the times builtin. * This file contains code for the times builtin.
* $Id: ash.c,v 1.55 2002/07/11 11:11:51 andersen Exp $ * $Id: ash.c,v 1.56 2002/08/02 06:39:47 aaronl Exp $
*/ */
static int timescmd (int argc, char **argv) static int timescmd (int argc, char **argv)
{ {