remove free NULL checks (Tilman Sauerbeck)

This commit is contained in:
christos 2016-01-17 17:45:21 +00:00
parent 4f3d9e304d
commit 59ef53c17c
10 changed files with 88 additions and 128 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: arch.c,v 1.66 2016/01/17 15:32:38 christos Exp $ */
/* $NetBSD: arch.c,v 1.67 2016/01/17 17:45:21 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: arch.c,v 1.66 2016/01/17 15:32:38 christos Exp $";
static char rcsid[] = "$NetBSD: arch.c,v 1.67 2016/01/17 17:45:21 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94";
#else
__RCSID("$NetBSD: arch.c,v 1.66 2016/01/17 15:32:38 christos Exp $");
__RCSID("$NetBSD: arch.c,v 1.67 2016/01/17 17:45:21 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -203,8 +203,7 @@ ArchFree(void *ap)
free(Hash_GetValue(entry));
free(a->name);
if (a->fnametab)
free(a->fnametab);
free(a->fnametab);
Hash_DeleteTable(&a->members);
free(a);
}
@ -261,8 +260,8 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt)
char *result;
result = Var_Parse(cp, ctxt, TRUE, TRUE, FALSE, &length, &freeIt);
if (freeIt)
free(freeIt);
free(freeIt);
if (result == var_Error) {
return(FAILURE);
} else {
@ -302,8 +301,8 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt)
char *result;
result = Var_Parse(cp, ctxt, TRUE, TRUE, FALSE, &length, &freeIt);
if (freeIt)
free(freeIt);
free(freeIt);
if (result == var_Error) {
return(FAILURE);
} else {
@ -710,8 +709,7 @@ ArchStatMember(char *archive, char *member, Boolean hash)
badarch:
fclose(arch);
Hash_DeleteTable(&ar->members);
if (ar->fnametab)
free(ar->fnametab);
free(ar->fnametab);
free(ar);
return NULL;
}
@ -996,10 +994,10 @@ Arch_Touch(GNode *gn)
arch = ArchFindMember(Var_Value(ARCHIVE, gn, &p1),
Var_Value(MEMBER, gn, &p2),
&arh, "r+");
if (p1)
free(p1);
if (p2)
free(p2);
free(p1);
free(p2);
snprintf(arh.ar_date, sizeof(arh.ar_date), "%-12ld", (long) now);
if (arch != NULL) {
@ -1078,10 +1076,9 @@ Arch_MTime(GNode *gn)
arhPtr = ArchStatMember(Var_Value(ARCHIVE, gn, &p1),
Var_Value(MEMBER, gn, &p2),
TRUE);
if (p1)
free(p1);
if (p2)
free(p2);
free(p1);
free(p2);
if (arhPtr != NULL) {
modTime = (time_t)strtol(arhPtr->ar_date, NULL, 10);

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat.c,v 1.102 2016/01/09 00:55:17 christos Exp $ */
/* $NetBSD: compat.c,v 1.103 2016/01/17 17:45:21 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: compat.c,v 1.102 2016/01/09 00:55:17 christos Exp $";
static char rcsid[] = "$NetBSD: compat.c,v 1.103 2016/01/17 17:45:21 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: compat.c,v 1.102 2016/01/09 00:55:17 christos Exp $");
__RCSID("$NetBSD: compat.c,v 1.103 2016/01/17 17:45:21 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -143,8 +143,8 @@ CompatInterrupt(int signo)
if (!noExecute && eunlink(file) != -1) {
Error("*** %s removed", file);
}
if (p1)
free(p1);
free(p1);
/*
* Run .INTERRUPT only if hit with interrupt signal
@ -371,10 +371,10 @@ again:
execError("exec", av[0]);
_exit(1);
}
if (mav)
free(mav);
if (bp)
free(bp);
free(mav);
free(bp);
Lst_Replace(cmdNode, NULL);
#ifdef USE_META
@ -513,8 +513,7 @@ Compat_Make(void *gnp, void *pgnp)
if (Lst_Member(gn->iParents, pgn) != NULL) {
char *p1;
Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
if (p1)
free(p1);
free(p1);
}
/*
@ -617,8 +616,7 @@ Compat_Make(void *gnp, void *pgnp)
if (Lst_Member(gn->iParents, pgn) != NULL) {
char *p1;
Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
if (p1)
free(p1);
free(p1);
}
switch(gn->made) {
case BEINGMADE:

View File

@ -1,4 +1,4 @@
/* $NetBSD: cond.c,v 1.72 2016/01/09 00:55:17 christos Exp $ */
/* $NetBSD: cond.c,v 1.73 2016/01/17 17:45:21 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: cond.c,v 1.72 2016/01/09 00:55:17 christos Exp $";
static char rcsid[] = "$NetBSD: cond.c,v 1.73 2016/01/17 17:45:21 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94";
#else
__RCSID("$NetBSD: cond.c,v 1.72 2016/01/09 00:55:17 christos Exp $");
__RCSID("$NetBSD: cond.c,v 1.73 2016/01/17 17:45:21 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -291,8 +291,7 @@ CondGetArg(char **linePtr, char **argPtr, const char *func)
cp2 = Var_Parse(cp, VAR_CMD, TRUE, TRUE, FALSE, &len, &freeIt);
Buf_AddBytes(&buf, strlen(cp2), cp2);
if (freeIt)
free(freeIt);
free(freeIt);
cp += len;
continue;
}
@ -346,8 +345,8 @@ CondDoDefined(int argLen MAKE_ATTR_UNUSED, const char *arg)
} else {
result = FALSE;
}
if (p1)
free(p1);
free(p1);
return (result);
}
@ -805,10 +804,8 @@ do_string_compare:
}
done:
if (lhsFree)
free(lhsFree);
if (rhsFree)
free(rhsFree);
free(lhsFree);
free(rhsFree);
return t;
}
@ -848,8 +845,7 @@ get_mpt_arg(char **linePtr, char **argPtr, const char *func MAKE_ATTR_UNUSED)
* true/false here.
*/
length = *val ? 2 : 1;
if (freeIt)
free(freeIt);
free(freeIt);
return length;
}
@ -900,8 +896,7 @@ compare_function(Boolean doEval)
}
/* Evaluate the argument using the required function. */
t = !doEval || fn_def->fn_proc(arglen, arg);
if (arg)
free(arg);
free(arg);
condExpr = cp;
return t;
}
@ -933,8 +928,7 @@ compare_function(Boolean doEval)
* be empty - even if it contained a variable expansion.
*/
t = !doEval || if_info->defProc(arglen, arg) != if_info->doNot;
if (arg)
free(arg);
free(arg);
return t;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: job.c,v 1.184 2016/01/17 15:32:38 christos Exp $ */
/* $NetBSD: job.c,v 1.185 2016/01/17 17:45:21 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: job.c,v 1.184 2016/01/17 15:32:38 christos Exp $";
static char rcsid[] = "$NetBSD: job.c,v 1.185 2016/01/17 17:45:21 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: job.c,v 1.184 2016/01/17 15:32:38 christos Exp $");
__RCSID("$NetBSD: job.c,v 1.185 2016/01/17 17:45:21 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -852,8 +852,7 @@ JobPrintCommand(void *cmdp, void *jobp)
DBPRINTF(cmdTemplate, cmd);
free(cmdStart);
if (escCmd)
free(escCmd);
free(escCmd);
if (errOff) {
/*
* If echoing is already off, there's no point in issuing the
@ -1219,8 +1218,7 @@ Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...))
*/
Make_HandleUse(DEFAULT, gn);
Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), gn, 0);
if (p1)
free(p1);
free(p1);
} else if (Dir_MTime(gn, 0) == 0 && (gn->type & OP_SPECIAL) == 0) {
/*
* The node wasn't the target of an operator we have no .DEFAULT
@ -2385,8 +2383,7 @@ Job_ParseShell(char *line)
line++;
}
if (shellArgv)
free(UNCONST(shellArgv));
free(UNCONST(shellArgv));
memset(&newShell, 0, sizeof(newShell));
@ -2634,8 +2631,7 @@ void
Job_End(void)
{
#ifdef CLEANUP
if (shellArgv)
free(shellArgv);
free(shellArgv);
#endif
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.237 2016/01/17 15:32:38 christos Exp $ */
/* $NetBSD: main.c,v 1.238 2016/01/17 17:45:21 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,7 +69,7 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: main.c,v 1.237 2016/01/17 15:32:38 christos Exp $";
static char rcsid[] = "$NetBSD: main.c,v 1.238 2016/01/17 17:45:21 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: main.c,v 1.237 2016/01/17 15:32:38 christos Exp $");
__RCSID("$NetBSD: main.c,v 1.238 2016/01/17 17:45:21 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -664,8 +664,7 @@ Main_ParseArgLine(const char *line)
buf = bmake_malloc(len = strlen(line) + strlen(argv0) + 2);
(void)snprintf(buf, len, "%s %s", argv0, line);
if (p1)
free(p1);
free(p1);
argv = brk_string(buf, &argc, TRUE, &args);
if (argv == NULL) {
@ -715,8 +714,7 @@ Main_SetObjdir(const char *path)
}
}
if (p)
free(p);
free(p);
return rc;
}
@ -787,8 +785,8 @@ MakeMode(const char *mode)
meta_mode_init(mode);
#endif
}
if (mp)
free(mp);
free(mp);
}
/*-
@ -1240,8 +1238,7 @@ main(int argc, char **argv)
MakeMode(NULL);
Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL);
if (p1)
free(p1);
free(p1);
if (!compatMake)
Job_ServerStart(maxJobTokens, jp_0, jp_1);
@ -1328,8 +1325,7 @@ main(int argc, char **argv)
value = Var_Value(var, VAR_GLOBAL, &p1);
}
printf("%s\n", value ? value : "");
if (p1)
free(p1);
free(p1);
}
} else {
/*
@ -1453,8 +1449,7 @@ ReadMakefile(const void *p, const void *q MAKE_ATTR_UNUSED)
name = Dir_FindFile(fname,
Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath);
if (!name || (fd = open(name, O_RDONLY)) == -1) {
if (name)
free(name);
free(name);
free(path);
return(-1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: make.c,v 1.93 2016/01/09 00:55:17 christos Exp $ */
/* $NetBSD: make.c,v 1.94 2016/01/17 17:45:21 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: make.c,v 1.93 2016/01/09 00:55:17 christos Exp $";
static char rcsid[] = "$NetBSD: make.c,v 1.94 2016/01/17 17:45:21 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)make.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: make.c,v 1.93 2016/01/09 00:55:17 christos Exp $");
__RCSID("$NetBSD: make.c,v 1.94 2016/01/17 17:45:21 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -482,8 +482,7 @@ Make_HandleUse(GNode *cgn, GNode *pgn)
if (gn->uname == NULL) {
gn->uname = gn->name;
} else {
if (gn->name)
free(gn->name);
free(gn->name);
}
gn->name = Var_Subst(NULL, gn->uname, pgn, FALSE, TRUE, FALSE);
if (gn->name && gn->uname && strcmp(gn->name, gn->uname) != 0) {
@ -692,8 +691,7 @@ Make_Update(GNode *cgn)
checked++;
cname = Var_Value(TARGET, cgn, &p1);
if (p1)
free(p1);
free(p1);
if (DEBUG(MAKE))
fprintf(debug_file, "Make_Update: %s%s\n", cgn->name, cgn->cohort_num);
@ -838,8 +836,7 @@ Make_Update(GNode *cgn)
Var_Set(PREFIX, cpref, pgn, 0);
}
}
if (p1)
free(p1);
free(p1);
Lst_Close(cgn->iParents);
}
}
@ -907,8 +904,7 @@ MakeAddAllSrc(void *cgnp, void *pgnp)
}
if (allsrc != NULL)
Var_Append(ALLSRC, allsrc, pgn);
if (p2)
free(p2);
free(p2);
if (pgn->type & OP_JOIN) {
if (cgn->made == MADE) {
Var_Append(OODATE, child, pgn);
@ -934,8 +930,7 @@ MakeAddAllSrc(void *cgnp, void *pgnp)
*/
Var_Append(OODATE, child, pgn);
}
if (p1)
free(p1);
free(p1);
}
return (0);
}
@ -981,8 +976,7 @@ Make_DoAllVar(GNode *gn)
if (gn->type & OP_JOIN) {
char *p1;
Var_Set(TARGET, Var_Value(ALLSRC, gn, &p1), gn, 0);
if (p1)
free(p1);
free(p1);
}
gn->flags |= DONE_ALLSRC;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: meta.c,v 1.43 2016/01/17 15:32:38 christos Exp $ */
/* $NetBSD: meta.c,v 1.44 2016/01/17 17:45:21 christos Exp $ */
/*
* Implement 'meta' mode.
@ -295,8 +295,7 @@ meta_name(struct GNode *gn, char *mname, size_t mnamelen,
}
free(tp);
for (i--; i >= 0; i--) {
if (p[i])
free(p[i]);
free(p[i]);
}
return (mname);
}
@ -348,8 +347,7 @@ is_submake(void *cmdp, void *gnp)
}
}
}
if (mp)
free(mp);
free(mp);
return (rc);
}
@ -369,8 +367,7 @@ printCMD(void *cmdp, void *mfpp)
cmd = cp = Var_Subst(NULL, cmd, mfp->gn, FALSE, TRUE);
}
fprintf(mfp->fp, "CMD %s\n", cmd);
if (cp)
free(cp);
free(cp);
return 0;
}
@ -519,8 +516,7 @@ meta_create(BuildMon *pbm, GNode *gn)
}
out:
for (i--; i >= 0; i--) {
if (p[i])
free(p[i]);
free(p[i]);
}
return (mf.fp);
@ -1030,14 +1026,12 @@ meta_oodate(GNode *gn, Boolean oodate)
ldir = Var_Value(ldir_vname, VAR_GLOBAL, &tp);
if (ldir) {
strlcpy(latestdir, ldir, sizeof(latestdir));
if (tp)
free(tp);
free(tp);
}
ldir = Var_Value(lcwd_vname, VAR_GLOBAL, &tp);
if (ldir) {
strlcpy(lcwd, ldir, sizeof(lcwd));
if (tp)
free(tp);
free(tp);
}
}
/* Skip past the pid. */
@ -1394,8 +1388,7 @@ meta_oodate(GNode *gn, Boolean oodate)
*/
Var_Delete(OODATE, gn);
Var_Set(OODATE, Var_Value(ALLSRC, gn, &cp), gn, 0);
if (cp)
free(cp);
free(cp);
}
return oodate;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.208 2016/01/17 15:32:38 christos Exp $ */
/* $NetBSD: parse.c,v 1.209 2016/01/17 17:45:21 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: parse.c,v 1.208 2016/01/17 15:32:38 christos Exp $";
static char rcsid[] = "$NetBSD: parse.c,v 1.209 2016/01/17 17:45:21 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: parse.c,v 1.208 2016/01/17 15:32:38 christos Exp $");
__RCSID("$NetBSD: parse.c,v 1.209 2016/01/17 17:45:21 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -1219,8 +1219,7 @@ ParseDoDependency(char *line)
void *freeIt;
(void)Var_Parse(cp, VAR_CMD, TRUE, TRUE, FALSE, &length, &freeIt);
if (freeIt)
free(freeIt);
free(freeIt);
cp += length-1;
}
}
@ -2324,10 +2323,8 @@ ParseSetIncludedFile(void)
fprintf(debug_file, "%s: ${.INCLUDEDFROMDIR} = `%s' "
"${.INCLUDEDFROMFILE} = `%s'\n", __func__, pd, pf);
if (fp)
free(fp);
if (dp)
free(dp);
free(fp);
free(dp);
}
/*-
*---------------------------------------------------------------------

View File

@ -1,4 +1,4 @@
/* $NetBSD: suff.c,v 1.76 2016/01/09 00:55:17 christos Exp $ */
/* $NetBSD: suff.c,v 1.77 2016/01/17 17:45:21 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: suff.c,v 1.76 2016/01/09 00:55:17 christos Exp $";
static char rcsid[] = "$NetBSD: suff.c,v 1.77 2016/01/17 17:45:21 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
#else
__RCSID("$NetBSD: suff.c,v 1.76 2016/01/09 00:55:17 christos Exp $");
__RCSID("$NetBSD: suff.c,v 1.77 2016/01/17 17:45:21 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -1614,8 +1614,7 @@ SuffExpandChildren(LstNode cln, GNode *pgn)
cp += len - 1;
}
if (freeIt)
free(freeIt);
free(freeIt);
} else if (*cp == '\\' && *cp != '\0') {
/*
* Escaped something -- skip over it
@ -1933,8 +1932,7 @@ SuffFindArchiveDeps(GNode *gn, Lst slst)
for (i = (sizeof(copy)/sizeof(copy[0]))-1; i >= 0; i--) {
char *p1;
Var_Set(copy[i], Var_Value(copy[i], mem, &p1), gn, 0);
if (p1)
free(p1);
free(p1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: targ.c,v 1.60 2015/05/25 09:01:06 manu Exp $ */
/* $NetBSD: targ.c,v 1.61 2016/01/17 17:45:21 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: targ.c,v 1.60 2015/05/25 09:01:06 manu Exp $";
static char rcsid[] = "$NetBSD: targ.c,v 1.61 2016/01/17 17:45:21 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: targ.c,v 1.60 2015/05/25 09:01:06 manu Exp $");
__RCSID("$NetBSD: targ.c,v 1.61 2016/01/17 17:45:21 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -292,10 +292,8 @@ TargFreeGN(void *gnp)
free(gn->name);
if (gn->uname)
free(gn->uname);
if (gn->path)
free(gn->path);
free(gn->uname);
free(gn->path);
/* gn->fname points to name allocated when file was opened, don't free */
Lst_Destroy(gn->iParents, NULL);