diff --git a/appl/rcp/util.c b/appl/rcp/util.c index 8d19f67d2..638c42a80 100644 --- a/appl/rcp/util.c +++ b/appl/rcp/util.c @@ -136,6 +136,7 @@ allocbuf(bp, fd, blksize) { struct stat stb; size_t size; + char *p; if (fstat(fd, &stb) < 0) { run_err("fstat: %s", strerror(errno)); @@ -146,11 +147,16 @@ 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); } + memset(p, 0, size); + bp->buf = p; bp->cnt = size; return (bp); }