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,7 +203,6 @@ ArchFree(void *ap)
free(Hash_GetValue(entry));
free(a->name);
if (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);
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);
if (result == var_Error) {
return(FAILURE);
} else {
@ -710,7 +709,6 @@ ArchStatMember(char *archive, char *member, Boolean hash)
badarch:
fclose(arch);
Hash_DeleteTable(&ar->members);
if (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);
snprintf(arh.ar_date, sizeof(arh.ar_date), "%-12ld", (long) now);
if (arch != NULL) {
@ -1078,9 +1076,8 @@ 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);
if (arhPtr != NULL) {

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,7 +143,7 @@ CompatInterrupt(int signo)
if (!noExecute && eunlink(file) != -1) {
Error("*** %s removed", file);
}
if (p1)
free(p1);
/*
@ -371,10 +371,10 @@ again:
execError("exec", av[0]);
_exit(1);
}
if (mav)
free(mav);
if (bp)
free(bp);
Lst_Replace(cmdNode, NULL);
#ifdef USE_META
@ -513,7 +513,6 @@ 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);
}
@ -617,7 +616,6 @@ 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);
}
switch(gn->made) {

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,7 +291,6 @@ 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);
cp += len;
continue;
@ -346,7 +345,7 @@ CondDoDefined(int argLen MAKE_ATTR_UNUSED, const char *arg)
} else {
result = FALSE;
}
if (p1)
free(p1);
return (result);
}
@ -805,9 +804,7 @@ do_string_compare:
}
done:
if (lhsFree)
free(lhsFree);
if (rhsFree)
free(rhsFree);
return t;
}
@ -848,7 +845,6 @@ get_mpt_arg(char **linePtr, char **argPtr, const char *func MAKE_ATTR_UNUSED)
* true/false here.
*/
length = *val ? 2 : 1;
if (freeIt)
free(freeIt);
return length;
}
@ -900,7 +896,6 @@ compare_function(Boolean doEval)
}
/* Evaluate the argument using the required function. */
t = !doEval || fn_def->fn_proc(arglen, arg);
if (arg)
free(arg);
condExpr = cp;
return t;
@ -933,7 +928,6 @@ 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);
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,7 +852,6 @@ JobPrintCommand(void *cmdp, void *jobp)
DBPRINTF(cmdTemplate, cmd);
free(cmdStart);
if (escCmd)
free(escCmd);
if (errOff) {
/*
@ -1219,7 +1218,6 @@ 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);
} else if (Dir_MTime(gn, 0) == 0 && (gn->type & OP_SPECIAL) == 0) {
/*
@ -2385,7 +2383,6 @@ Job_ParseShell(char *line)
line++;
}
if (shellArgv)
free(UNCONST(shellArgv));
memset(&newShell, 0, sizeof(newShell));
@ -2634,7 +2631,6 @@ void
Job_End(void)
{
#ifdef CLEANUP
if (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,7 +664,6 @@ 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);
argv = brk_string(buf, &argc, TRUE, &args);
@ -715,7 +714,6 @@ Main_SetObjdir(const char *path)
}
}
if (p)
free(p);
return rc;
}
@ -787,7 +785,7 @@ MakeMode(const char *mode)
meta_mode_init(mode);
#endif
}
if (mp)
free(mp);
}
@ -1240,7 +1238,6 @@ main(int argc, char **argv)
MakeMode(NULL);
Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL);
if (p1)
free(p1);
if (!compatMake)
@ -1328,7 +1325,6 @@ main(int argc, char **argv)
value = Var_Value(var, VAR_GLOBAL, &p1);
}
printf("%s\n", value ? value : "");
if (p1)
free(p1);
}
} else {
@ -1453,7 +1449,6 @@ 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(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,7 +482,6 @@ Make_HandleUse(GNode *cgn, GNode *pgn)
if (gn->uname == NULL) {
gn->uname = gn->name;
} else {
if (gn->name)
free(gn->name);
}
gn->name = Var_Subst(NULL, gn->uname, pgn, FALSE, TRUE, FALSE);
@ -692,7 +691,6 @@ Make_Update(GNode *cgn)
checked++;
cname = Var_Value(TARGET, cgn, &p1);
if (p1)
free(p1);
if (DEBUG(MAKE))
@ -838,7 +836,6 @@ Make_Update(GNode *cgn)
Var_Set(PREFIX, cpref, pgn, 0);
}
}
if (p1)
free(p1);
Lst_Close(cgn->iParents);
}
@ -907,7 +904,6 @@ MakeAddAllSrc(void *cgnp, void *pgnp)
}
if (allsrc != NULL)
Var_Append(ALLSRC, allsrc, pgn);
if (p2)
free(p2);
if (pgn->type & OP_JOIN) {
if (cgn->made == MADE) {
@ -934,7 +930,6 @@ MakeAddAllSrc(void *cgnp, void *pgnp)
*/
Var_Append(OODATE, child, pgn);
}
if (p1)
free(p1);
}
return (0);
@ -981,7 +976,6 @@ 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);
}
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,7 +295,6 @@ meta_name(struct GNode *gn, char *mname, size_t mnamelen,
}
free(tp);
for (i--; i >= 0; i--) {
if (p[i])
free(p[i]);
}
return (mname);
@ -348,7 +347,6 @@ is_submake(void *cmdp, void *gnp)
}
}
}
if (mp)
free(mp);
return (rc);
}
@ -369,7 +367,6 @@ 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);
return 0;
}
@ -519,7 +516,6 @@ meta_create(BuildMon *pbm, GNode *gn)
}
out:
for (i--; i >= 0; i--) {
if (p[i])
free(p[i]);
}
@ -1030,13 +1026,11 @@ 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);
}
ldir = Var_Value(lcwd_vname, VAR_GLOBAL, &tp);
if (ldir) {
strlcpy(lcwd, ldir, sizeof(lcwd));
if (tp)
free(tp);
}
}
@ -1394,7 +1388,6 @@ meta_oodate(GNode *gn, Boolean oodate)
*/
Var_Delete(OODATE, gn);
Var_Set(OODATE, Var_Value(ALLSRC, gn, &cp), gn, 0);
if (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,7 +1219,6 @@ ParseDoDependency(char *line)
void *freeIt;
(void)Var_Parse(cp, VAR_CMD, TRUE, TRUE, FALSE, &length, &freeIt);
if (freeIt)
free(freeIt);
cp += length-1;
}
@ -2324,9 +2323,7 @@ ParseSetIncludedFile(void)
fprintf(debug_file, "%s: ${.INCLUDEDFROMDIR} = `%s' "
"${.INCLUDEDFROMFILE} = `%s'\n", __func__, pd, pf);
if (fp)
free(fp);
if (dp)
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,7 +1614,6 @@ SuffExpandChildren(LstNode cln, GNode *pgn)
cp += len - 1;
}
if (freeIt)
free(freeIt);
} else if (*cp == '\\' && *cp != '\0') {
/*
@ -1933,7 +1932,6 @@ 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);
}

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,9 +292,7 @@ TargFreeGN(void *gnp)
free(gn->name);
if (gn->uname)
free(gn->uname);
if (gn->path)
free(gn->path);
/* gn->fname points to name allocated when file was opened, don't free */