summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2015-09-14 16:09:14 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2015-09-14 16:09:14 +0000
commit9ff6142e17078f6ac126c5b59f3fbf60786dd768 (patch)
tree2bcc4313c545a6bc86ca7d6743793d287b61b0f1
parentddd8533a3041026de9cbd67293774693d57c91c3 (diff)
remove null check before free. from Michael McConville
ok semarie
-rw-r--r--lib/libc/gen/auth_subr.c26
-rw-r--r--lib/libc/gen/authenticate.c8
-rw-r--r--lib/libc/gen/fts.c17
-rw-r--r--lib/libc/gen/getcap.c26
-rw-r--r--lib/libc/gen/getgrent.c8
-rw-r--r--lib/libc/gen/getmntinfo.c5
-rw-r--r--lib/libc/gen/getnetgrent.c29
-rw-r--r--lib/libc/gen/getpwent.c35
-rw-r--r--lib/libc/gen/getusershell.c14
-rw-r--r--lib/libc/gen/glob.c8
-rw-r--r--lib/libc/gen/login_cap.c44
11 files changed, 77 insertions, 143 deletions
diff --git a/lib/libc/gen/auth_subr.c b/lib/libc/gen/auth_subr.c
index f35b5741522..26d93b48c8c 100644
--- a/lib/libc/gen/auth_subr.c
+++ b/lib/libc/gen/auth_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth_subr.c,v 1.44 2015/09/12 15:20:14 guenther Exp $ */
+/* $OpenBSD: auth_subr.c,v 1.45 2015/09/14 16:09:13 tedu Exp $ */
/*
* Copyright (c) 2000-2002,2004 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -284,14 +284,10 @@ auth_close(auth_session_t *as)
*/
if (as->service && as->service != defservice)
free(as->service);
- if (as->challenge)
- free(as->challenge);
- if (as->class)
- free(as->class);
- if (as->style)
- free(as->style);
- if (as->name)
- free(as->name);
+ free(as->challenge);
+ free(as->class);
+ free(as->style);
+ free(as->name);
free(as);
return (s);
@@ -466,8 +462,7 @@ auth_setitem(auth_session_t *as, auth_item_t item, char *value)
return (0);
if (value != NULL && (value = strdup(value)) == NULL)
return (-1);
- if (as->challenge)
- free(as->challenge);
+ free(as->challenge);
as->challenge = value;
return (0);
@@ -476,8 +471,7 @@ auth_setitem(auth_session_t *as, auth_item_t item, char *value)
return (0);
if (value != NULL && (value = strdup(value)) == NULL)
return (-1);
- if (as->class)
- free(as->class);
+ free(as->class);
as->class = value;
return (0);
@@ -486,8 +480,7 @@ auth_setitem(auth_session_t *as, auth_item_t item, char *value)
return (0);
if (value != NULL && (value = strdup(value)) == NULL)
return (-1);
- if (as->name)
- free(as->name);
+ free(as->name);
as->name = value;
return (0);
@@ -509,8 +502,7 @@ auth_setitem(auth_session_t *as, auth_item_t item, char *value)
if (value == NULL || strchr(value, '/') != NULL ||
(value = strdup(value)) == NULL)
return (-1);
- if (as->style)
- free(as->style);
+ free(as->style);
as->style = value;
return (0);
diff --git a/lib/libc/gen/authenticate.c b/lib/libc/gen/authenticate.c
index 3043836777a..80ff4ebab1a 100644
--- a/lib/libc/gen/authenticate.c
+++ b/lib/libc/gen/authenticate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: authenticate.c,v 1.23 2015/09/12 15:20:14 guenther Exp $ */
+/* $OpenBSD: authenticate.c,v 1.24 2015/09/14 16:09:13 tedu Exp $ */
/*-
* Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved.
@@ -259,8 +259,7 @@ auth_approval(auth_session_t *as, login_cap_t *lc, char *name, char *type)
login_close(lc);
syslog(LOG_ERR, "%m");
warn(NULL);
- if (approve)
- free(approve);
+ free(approve);
return (0);
}
@@ -294,8 +293,7 @@ auth_approval(auth_session_t *as, login_cap_t *lc, char *name, char *type)
lc->lc_class, type, (char *)NULL);
out:
- if (approve)
- free(approve);
+ free(approve);
if (close_lc_on_exit)
login_close(lc);
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
index 88b9bfcd0da..3f581a38994 100644
--- a/lib/libc/gen/fts.c
+++ b/lib/libc/gen/fts.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fts.c,v 1.51 2015/09/12 13:32:24 guenther Exp $ */
+/* $OpenBSD: fts.c,v 1.52 2015/09/14 16:09:13 tedu Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -228,8 +228,7 @@ fts_close(FTS *sp)
/* Free up child linked list, sort array, path buffer, stream ptr.*/
if (sp->fts_child)
fts_lfree(sp->fts_child);
- if (sp->fts_array)
- free(sp->fts_array);
+ free(sp->fts_array);
free(sp->fts_path);
free(sp);
@@ -668,8 +667,7 @@ fts_build(FTS *sp, int type)
* structures already allocated.
*/
mem1: saved_errno = errno;
- if (p)
- free(p);
+ free(p);
fts_lfree(head);
(void)closedir(dirp);
cur->fts_info = FTS_ERR;
@@ -889,8 +887,7 @@ fts_sort(FTS *sp, FTSENT *head, int nitems)
sp->fts_nitems = nitems + 40;
if ((a = reallocarray(sp->fts_array,
sp->fts_nitems, sizeof(FTSENT *))) == NULL) {
- if (sp->fts_array)
- free(sp->fts_array);
+ free(sp->fts_array);
sp->fts_array = NULL;
sp->fts_nitems = 0;
return (head);
@@ -964,8 +961,7 @@ fts_palloc(FTS *sp, size_t more)
*/
more += 256;
if (sp->fts_pathlen + more < sp->fts_pathlen) {
- if (sp->fts_path)
- free(sp->fts_path);
+ free(sp->fts_path);
sp->fts_path = NULL;
errno = ENAMETOOLONG;
return (1);
@@ -973,8 +969,7 @@ fts_palloc(FTS *sp, size_t more)
sp->fts_pathlen += more;
p = realloc(sp->fts_path, sp->fts_pathlen);
if (p == NULL) {
- if (sp->fts_path)
- free(sp->fts_path);
+ free(sp->fts_path);
sp->fts_path = NULL;
return (1);
}
diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c
index fff16280c49..5b9f812653b 100644
--- a/lib/libc/gen/getcap.c
+++ b/lib/libc/gen/getcap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getcap.c,v 1.32 2015/09/13 08:31:47 guenther Exp $ */
+/* $OpenBSD: getcap.c,v 1.33 2015/09/14 16:09:13 tedu Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -87,8 +87,7 @@ int
cgetset(const char *ent)
{
if (ent == NULL) {
- if (toprec)
- free(toprec);
+ free(toprec);
toprec = NULL;
topreclen = 0;
return (0);
@@ -354,8 +353,7 @@ getent(char **cap, u_int *len, char **db_array, FILE *fp,
newsize = r_end - record + BFRAG;
nrecord = realloc(record, newsize);
if (nrecord == NULL) {
- if (record)
- free(record);
+ free(record);
if (myfd)
(void)fclose(fp);
errno = ENOMEM;
@@ -498,8 +496,7 @@ tc_exp: {
tcposend = tcend - record;
nrecord = realloc(record, newsize);
if (nrecord == NULL) {
- if (record)
- free(record);
+ free(record);
if (myfd)
(void)fclose(fp);
free(ibuf);
@@ -542,8 +539,7 @@ tc_exp: {
if ((nrecord =
realloc(record, (size_t)(rp - record))) == NULL) {
- if (record)
- free(record);
+ free(record);
errno = ENOMEM;
return (-2);
}
@@ -910,8 +906,7 @@ cgetstr(char *buf, const char *cap, char **str)
char *nmem;
if ((nmem = realloc(mem, size + SFRAG)) == NULL) {
- if (mem)
- free(mem);
+ free(mem);
return (-2);
}
mem = nmem;
@@ -930,8 +925,7 @@ cgetstr(char *buf, const char *cap, char **str)
char *nmem;
if ((nmem = realloc(mem, (size_t)(mp - mem))) == NULL) {
- if (mem)
- free(mem);
+ free(mem);
return (-2);
}
mem = nmem;
@@ -993,8 +987,7 @@ cgetustr(char *buf, const char *cap, char **str)
char *nmem;
if ((nmem = realloc(mem, size + SFRAG)) == NULL) {
- if (mem)
- free(mem);
+ free(mem);
return (-2);
}
mem = nmem;
@@ -1013,8 +1006,7 @@ cgetustr(char *buf, const char *cap, char **str)
char *nmem;
if ((nmem = realloc(mem, mp - mem)) == NULL) {
- if (mem)
- free(mem);
+ free(mem);
return (-2);
}
mem = nmem;
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c
index f0f4c054ebb..e42fd57bc7d 100644
--- a/lib/libc/gen/getgrent.c
+++ b/lib/libc/gen/getgrent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getgrent.c,v 1.43 2015/09/13 12:20:12 guenther Exp $ */
+/* $OpenBSD: getgrent.c,v 1.44 2015/09/14 16:09:13 tedu Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -199,8 +199,7 @@ start_gr(void)
rewind(_gr_fp);
#ifdef YP
__ypmode = 0;
- if (__ypcurrent)
- free(__ypcurrent);
+ free(__ypcurrent);
__ypcurrent = NULL;
if (__ypexhead)
__ypexclude_free(&__ypexhead);
@@ -251,8 +250,7 @@ endgrent_basic(void)
_gr_fp = NULL;
#ifdef YP
__ypmode = 0;
- if (__ypcurrent)
- free(__ypcurrent);
+ free(__ypcurrent);
__ypcurrent = NULL;
if (__ypexhead)
__ypexclude_free(&__ypexhead);
diff --git a/lib/libc/gen/getmntinfo.c b/lib/libc/gen/getmntinfo.c
index 285687e45f4..4ba27ce14a3 100644
--- a/lib/libc/gen/getmntinfo.c
+++ b/lib/libc/gen/getmntinfo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getmntinfo.c,v 1.9 2015/08/20 21:49:29 deraadt Exp $ */
+/* $OpenBSD: getmntinfo.c,v 1.10 2015/09/14 16:09:13 tedu Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -47,8 +47,7 @@ getmntinfo(struct statfs **mntbufp, int flags)
if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, flags)) < 0)
return (0);
while (bufsize <= mntsize * sizeof(struct statfs)) {
- if (mntbuf)
- free(mntbuf);
+ free(mntbuf);
bufsize = (mntsize + 1) * sizeof(struct statfs);
if ((mntbuf = malloc(bufsize)) == 0) {
bufsize = 0;
diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c
index ee90eae1be5..82ad23f5474 100644
--- a/lib/libc/gen/getnetgrent.c
+++ b/lib/libc/gen/getnetgrent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getnetgrent.c,v 1.26 2015/09/14 10:44:40 guenther Exp $ */
+/* $OpenBSD: getnetgrent.c,v 1.27 2015/09/14 16:09:13 tedu Exp $ */
/*
* Copyright (c) 1994 Christos Zoulas
@@ -233,11 +233,9 @@ getnetgroup(char **pp)
return ng;
baddomain:
- if (ng->ng_user)
- free(ng->ng_user);
+ free(ng->ng_user);
baduser:
- if (ng->ng_host)
- free(ng->ng_host);
+ free(ng->ng_host);
badhost:
free(ng);
return NULL;
@@ -477,12 +475,9 @@ in_find(char *ypdom, struct stringlist *sl, char *grp, const char *host,
case _NG_GROUP:
/* new netgroup */
i = in_check(host, user, domain, ng);
- if (ng->ng_host != NULL)
- free(ng->ng_host);
- if (ng->ng_user != NULL)
- free(ng->ng_user);
- if (ng->ng_domain != NULL)
- free(ng->ng_domain);
+ free(ng->ng_host);
+ free(ng->ng_user);
+ free(ng->ng_domain);
free(ng);
if (i) {
free(line);
@@ -605,12 +600,9 @@ endnetgrent(void)
{
for (_nglist = _nghead; _nglist != NULL; _nglist = _nghead) {
_nghead = _nglist->ng_next;
- if (_nglist->ng_host != NULL)
- free(_nglist->ng_host);
- if (_nglist->ng_user != NULL)
- free(_nglist->ng_user);
- if (_nglist->ng_domain != NULL)
- free(_nglist->ng_domain);
+ free(_nglist->ng_host);
+ free(_nglist->ng_user);
+ free(_nglist->ng_domain);
free(_nglist);
}
@@ -701,8 +693,7 @@ innetgr(const char *grp, const char *host, const char *user, const char *domain)
else if (lookup(NULL, "+", &line, _NG_KEYBYNAME) == 0)
yp_get_default_domain(&ypdom);
- if (line)
- free(line);
+ free(line);
#endif
/* Try the fast lookup first */
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c
index f7b7d37b926..3d365bf59f9 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getpwent.c,v 1.55 2015/09/13 15:33:48 guenther Exp $ */
+/* $OpenBSD: getpwent.c,v 1.56 2015/09/14 16:09:13 tedu Exp $ */
/*
* Copyright (c) 2008 Theo de Raadt
* Copyright (c) 1988, 1993
@@ -294,8 +294,7 @@ again:
__ypcurrent = NULL;
if (r != 0) {
__ypmode = YPMODE_NONE;
- if (data)
- free(data);
+ free(data);
goto again;
}
__ypcurrent = key;
@@ -307,8 +306,7 @@ again:
if (r != 0 ||
__ypcurrentlen > sizeof(__ypline)) {
__ypmode = YPMODE_NONE;
- if (data)
- free(data);
+ free(data);
goto again;
}
}
@@ -333,8 +331,7 @@ again:
* if the netgroup is invalid, keep looking
* as there may be valid users later on.
*/
- if (data)
- free(data);
+ free(data);
goto again;
}
bcopy(data, __ypline, datalen);
@@ -349,8 +346,7 @@ again:
name = NULL;
if (r != 0 ||
__ypcurrentlen > sizeof(__ypline)) {
- if (data)
- free(data);
+ free(data);
goto again;
}
bcopy(data, __ypline, datalen);
@@ -506,8 +502,7 @@ __has_ypmaster(void)
return (checked);
}
free(result);
- if (key)
- free(key);
+ free(key);
saved_uid = uid;
saved_euid = euid;
@@ -566,8 +561,7 @@ __yppwlookup(int lookup, char *name, uid_t uid, struct passwd *pw,
name, strlen(name),
&ypcurrent, &ypcurrentlen);
if (r != 0 || ypcurrentlen > buflen) {
- if (ypcurrent)
- free(ypcurrent);
+ free(ypcurrent);
ypcurrent = NULL;
continue;
}
@@ -593,8 +587,7 @@ pwnam_netgrp:
} else
goto pwnam_netgrp;
if (r != 0 || ypcurrentlen > buflen) {
- if (ypcurrent)
- free(ypcurrent);
+ free(ypcurrent);
ypcurrent = NULL;
/*
* just because this
@@ -615,8 +608,7 @@ pwnam_netgrp:
user, strlen(user),
&ypcurrent, &ypcurrentlen);
if (r != 0 || ypcurrentlen > buflen) {
- if (ypcurrent)
- free(ypcurrent);
+ free(ypcurrent);
ypcurrent = NULL;
continue;
}
@@ -661,8 +653,7 @@ pwnam_netgrp:
done:
__ypexclude_free(&ypexhead);
__ypproto = NULL;
- if (ypcurrent)
- free(ypcurrent);
+ free(ypcurrent);
ypcurrent = NULL;
if (map)
free(name);
@@ -840,8 +831,7 @@ setpassent(int stayopen)
_pw_stayopen = stayopen;
#ifdef YP
__ypmode = YPMODE_NONE;
- if (__ypcurrent)
- free(__ypcurrent);
+ free(__ypcurrent);
__ypcurrent = NULL;
__ypexclude_free(&__ypexhead);
__ypproto = NULL;
@@ -871,8 +861,7 @@ endpwent(void)
}
#ifdef YP
__ypmode = YPMODE_NONE;
- if (__ypcurrent)
- free(__ypcurrent);
+ free(__ypcurrent);
__ypcurrent = NULL;
__ypexclude_free(&__ypexhead);
__ypproto = NULL;
diff --git a/lib/libc/gen/getusershell.c b/lib/libc/gen/getusershell.c
index 0bcbf0b0464..c835f4ddbe9 100644
--- a/lib/libc/gen/getusershell.c
+++ b/lib/libc/gen/getusershell.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getusershell.c,v 1.15 2015/02/06 23:21:58 millert Exp $ */
+/* $OpenBSD: getusershell.c,v 1.16 2015/09/14 16:09:13 tedu Exp $ */
/*
* Copyright (c) 1985, 1993
* The Regents of the University of California. All rights reserved.
@@ -67,11 +67,9 @@ void
endusershell(void)
{
- if (shells != NULL)
- free(shells);
+ free(shells);
shells = NULL;
- if (strings != NULL)
- free(strings);
+ free(strings);
strings = NULL;
curshell = NULL;
}
@@ -90,11 +88,9 @@ initshells(void)
FILE *fp;
struct stat statb;
- if (shells != NULL)
- free(shells);
+ free(shells);
shells = NULL;
- if (strings != NULL)
- free(strings);
+ free(strings);
strings = NULL;
if ((fp = fopen(_PATH_SHELLS, "re")) == NULL)
return (okshells);
diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c
index 27003b3be99..5d7037a2357 100644
--- a/lib/libc/gen/glob.c
+++ b/lib/libc/gen/glob.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: glob.c,v 1.43 2015/06/13 16:57:04 deraadt Exp $ */
+/* $OpenBSD: glob.c,v 1.44 2015/09/14 16:09:13 tedu Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -954,15 +954,13 @@ globfree(glob_t *pglob)
if (pglob->gl_pathv != NULL) {
pp = pglob->gl_pathv + pglob->gl_offs;
for (i = pglob->gl_pathc; i--; ++pp)
- if (*pp)
- free(*pp);
+ free(*pp);
free(pglob->gl_pathv);
pglob->gl_pathv = NULL;
}
if (pglob->gl_statv != NULL) {
for (i = 0; i < pglob->gl_pathc; i++) {
- if (pglob->gl_statv[i] != NULL)
- free(pglob->gl_statv[i]);
+ free(pglob->gl_statv[i]);
}
free(pglob->gl_statv);
pglob->gl_statv = NULL;
diff --git a/lib/libc/gen/login_cap.c b/lib/libc/gen/login_cap.c
index 1fd59d8b8bd..ccbd303bf91 100644
--- a/lib/libc/gen/login_cap.c
+++ b/lib/libc/gen/login_cap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: login_cap.c,v 1.31 2015/09/13 19:58:50 guenther Exp $ */
+/* $OpenBSD: login_cap.c,v 1.32 2015/09/14 16:09:13 tedu Exp $ */
/*
* Copyright (c) 2000-2004 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -209,10 +209,8 @@ login_getstyle(login_cap_t *lc, char *style, char *atype)
if (lc->lc_style == NULL)
syslog(LOG_ERR, "strdup: %m");
}
- if (f1)
- free(f1);
- if (f2)
- free(f2);
+ free(f1);
+ free(f2);
return (lc->lc_style);
}
DEF_WEAK(login_getstyle);
@@ -270,12 +268,10 @@ login_getcaptime(login_cap_t *lc, char *cap, quad_t def, quad_t e)
switch (stat = cgetstr(lc->lc_cap, cap, &res)) {
case -1:
- if (res)
- free(res);
+ free(res);
return (def);
case -2:
- if (res)
- free(res);
+ free(res);
syslog(LOG_ERR, "%s: getting capability %s: %m",
lc->lc_class, cap);
errno = ERANGE;
@@ -283,8 +279,7 @@ login_getcaptime(login_cap_t *lc, char *cap, quad_t def, quad_t e)
default:
if (stat >= 0)
break;
- if (res)
- free(res);
+ free(res);
syslog(LOG_ERR, "%s: unexpected error with capability %s",
lc->lc_class, cap);
errno = ERANGE;
@@ -359,12 +354,10 @@ login_getcapnum(login_cap_t *lc, char *cap, quad_t def, quad_t e)
switch (stat = cgetstr(lc->lc_cap, cap, &res)) {
case -1:
- if (res)
- free(res);
+ free(res);
return (def);
case -2:
- if (res)
- free(res);
+ free(res);
syslog(LOG_ERR, "%s: getting capability %s: %m",
lc->lc_class, cap);
errno = ERANGE;
@@ -372,8 +365,7 @@ login_getcapnum(login_cap_t *lc, char *cap, quad_t def, quad_t e)
default:
if (stat >= 0)
break;
- if (res)
- free(res);
+ free(res);
syslog(LOG_ERR, "%s: unexpected error with capability %s",
lc->lc_class, cap);
errno = ERANGE;
@@ -417,12 +409,10 @@ login_getcapsize(login_cap_t *lc, char *cap, quad_t def, quad_t e)
switch (stat = cgetstr(lc->lc_cap, cap, &res)) {
case -1:
- if (res)
- free(res);
+ free(res);
return (def);
case -2:
- if (res)
- free(res);
+ free(res);
syslog(LOG_ERR, "%s: getting capability %s: %m",
lc->lc_class, cap);
errno = ERANGE;
@@ -430,8 +420,7 @@ login_getcapsize(login_cap_t *lc, char *cap, quad_t def, quad_t e)
default:
if (stat >= 0)
break;
- if (res)
- free(res);
+ free(res);
syslog(LOG_ERR, "%s: unexpected error with capability %s",
lc->lc_class, cap);
errno = ERANGE;
@@ -467,12 +456,9 @@ void
login_close(login_cap_t *lc)
{
if (lc) {
- if (lc->lc_class)
- free(lc->lc_class);
- if (lc->lc_cap)
- free(lc->lc_cap);
- if (lc->lc_style)
- free(lc->lc_style);
+ free(lc->lc_class);
+ free(lc->lc_cap);
+ free(lc->lc_style);
free(lc);
}
}