diff options
author | 1998-08-15 20:14:08 +0000 | |
---|---|---|
committer | 1998-08-15 20:14:08 +0000 | |
commit | f652cbcbae649cd6283f68decf96b84ea82efeaf (patch) | |
tree | 03ba2a8bc4433b0dd52cdadb0e558062b5a6ef94 /bin | |
parent | simplify a few things wrt realloc (diff) | |
download | wireguard-openbsd-f652cbcbae649cd6283f68decf96b84ea82efeaf.tar.xz wireguard-openbsd-f652cbcbae649cd6283f68decf96b84ea82efeaf.zip |
fix realloc
Diffstat (limited to 'bin')
-rw-r--r-- | bin/rcp/util.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/bin/rcp/util.c b/bin/rcp/util.c index 9380ed08c45..7d268a5e78c 100644 --- a/bin/rcp/util.c +++ b/bin/rcp/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.5 1997/09/01 18:30:24 deraadt Exp $ */ +/* $OpenBSD: util.c,v 1.6 1998/08/15 20:14:08 deraadt Exp $ */ /* $NetBSD: util.c,v 1.2 1995/03/21 08:19:08 cgd Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)util.c 8.2 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: util.c,v 1.5 1997/09/01 18:30:24 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: util.c,v 1.6 1998/08/15 20:14:08 deraadt Exp $"; #endif #endif /* not lint */ @@ -143,6 +143,7 @@ allocbuf(bp, fd, blksize) { struct stat stb; size_t size; + char *p; if (fstat(fd, &stb) < 0) { run_err("fstat: %s", strerror(errno)); @@ -153,11 +154,15 @@ allocbuf(bp, fd, blksize) size = blksize; if (bp->cnt >= size) return (bp); - if ((bp->buf = realloc(bp->buf, size)) == NULL) { + if ((p = realloc(bp->buf, size)) == NULL) { + if (bp->buf) + free(bp->buf); + bp->buf = NULL; bp->cnt = 0; run_err("%s", strerror(errno)); return (0); } + bp->buf = p; bp->cnt = size; return (bp); } |