From 9a2ca4d7379e33069db491536c32a9549abb5e11 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Thu, 25 Sep 2003 04:15:30 +0000 Subject: p = realloc(p is not allowed --- sbin/fsck/fsutil.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sbin/fsck/fsutil.c b/sbin/fsck/fsutil.c index 83770177f7a..11253bf2bef 100644 --- a/sbin/fsck/fsutil.c +++ b/sbin/fsck/fsutil.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fsutil.c,v 1.12 2003/07/29 18:38:35 deraadt Exp $ */ +/* $OpenBSD: fsutil.c,v 1.13 2003/09/25 04:15:29 deraadt Exp $ */ /* $NetBSD: fsutil.c,v 1.2 1996/10/03 20:06:31 christos Exp $ */ /* @@ -30,7 +30,7 @@ * SUCH DAMAGE. */ #ifndef lint -static const char rcsid[] = "$OpenBSD: fsutil.c,v 1.12 2003/07/29 18:38:35 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: fsutil.c,v 1.13 2003/09/25 04:15:29 deraadt Exp $"; #endif /* not lint */ #include @@ -246,12 +246,17 @@ emalloc(size_t s) void * erealloc(void *p, size_t s) { + void *newp; + if (s == 0) err(1, "realloc failed"); - p = realloc(p, s); - if (p == NULL) + newp = realloc(p, s); + if (newp == NULL) { + if (p) + free(p); err(1, "realloc failed"); - return p; + } + return newp; } -- cgit v1.2.3