summaryrefslogtreecommitdiff
path: root/bin/rcp/util.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1998-08-15 20:14:09 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1998-08-15 20:14:09 +0000
commiteb305ae061e907240c6eb8168b79d51f025e5d07 (patch)
treea173759b2b33a01cd17f9b071312f47d67171b19 /bin/rcp/util.c
parenteff1ef758b0ad22d72d2d0e6691e0dcf09870f56 (diff)
fix realloc
Diffstat (limited to 'bin/rcp/util.c')
-rw-r--r--bin/rcp/util.c11
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);
}