From 34c2ea26dbd0467fffc3171c64f86b5b2ffad4d8 Mon Sep 17 00:00:00 2001 From: deraadt Date: Fri, 29 May 2015 15:57:36 +0000 Subject: [PATCH] do not need non-NULL-check before free(p), other minor refactoring from Benjamin Baier --- sbin/fsck/fsck.c | 10 ++++------ sbin/fsck/fsutil.c | 9 +++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/sbin/fsck/fsck.c b/sbin/fsck/fsck.c index 2e12254bf89..51bb4b3d41c 100644 --- a/sbin/fsck/fsck.c +++ b/sbin/fsck/fsck.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fsck.c,v 1.36 2015/05/29 15:53:46 deraadt Exp $ */ +/* $OpenBSD: fsck.c,v 1.37 2015/05/29 15:57:36 deraadt Exp $ */ /* $NetBSD: fsck.c,v 1.7 1996/10/03 20:06:30 christos Exp $ */ /* @@ -287,8 +287,7 @@ checkfs(const char *vfstype, const char *spec, const char *mntpt, void *auxarg, switch (pid = fork()) { case -1: /* Error. */ warn("fork"); - if (optbuf) - free(optbuf); + free(optbuf); free(argv); return (1); @@ -320,8 +319,7 @@ checkfs(const char *vfstype, const char *spec, const char *mntpt, void *auxarg, /* NOTREACHED */ default: /* Parent. */ - if (optbuf) - free(optbuf); + free(optbuf); free(argv); if (pidp) { @@ -439,7 +437,7 @@ catopt(char *s0, const char *s1, int fr) } else cp = estrdup(s1); - if (s0 && fr) + if (fr) free(s0); return (cp); } diff --git a/sbin/fsck/fsutil.c b/sbin/fsck/fsutil.c index e18335d1a95..703872b5f78 100644 --- a/sbin/fsck/fsutil.c +++ b/sbin/fsck/fsutil.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fsutil.c,v 1.20 2015/01/16 06:39:57 deraadt Exp $ */ +/* $OpenBSD: fsutil.c,v 1.21 2015/05/29 15:57:36 deraadt Exp $ */ /* $NetBSD: fsutil.c,v 1.2 1996/10/03 20:06:31 christos Exp $ */ /* @@ -252,12 +252,13 @@ ereallocarray(void *p, size_t n, size_t s) { void *newp; - if (s == 0) + if (n == 0 || s == 0) { + free(p); err(1, "realloc failed"); + } newp = reallocarray(p, n, s); if (newp == NULL) { - if (p) - free(p); + free(p); err(1, "realloc failed"); } return newp; -- 2.20.1