From e706d29ccaaa0a310334186638a0b989a0dfbca5 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Tue, 4 Sep 2001 14:35:58 +0000 Subject: [PATCH] (allocbuf): do not leak memory on failure and zero re-used memory, from Markus Friedl git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@10657 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/rcp/util.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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); }