aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/tail
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2007-10-17 09:52:08 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2007-10-17 09:52:08 +0000
commit7ce8354a9bf58ba0433d798d97bb890379c365d9 (patch)
tree31fb9938b56dbf9e527e0383282c05631cdd4733 /usr.bin/tail
parentafb6c26e9e8d4689f63947a001c84f2d3ffa69f6 (diff)
downloadsrc-7ce8354a9bf58ba0433d798d97bb890379c365d9.tar.gz
src-7ce8354a9bf58ba0433d798d97bb890379c365d9.zip
Fix various memory leaks.
Submitted by: rdivacky Obtained from: OpenBSD MFC after: 1 week
Notes
Notes: svn path=/head/; revision=172719
Diffstat (limited to 'usr.bin/tail')
-rw-r--r--usr.bin/tail/read.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/usr.bin/tail/read.c b/usr.bin/tail/read.c
index ff66f78cf37e..d04d158d47f6 100644
--- a/usr.bin/tail/read.c
+++ b/usr.bin/tail/read.c
@@ -85,6 +85,7 @@ bytes(FILE *fp, off_t off)
}
if (ferror(fp)) {
ierr();
+ free(sp);
return 1;
}
@@ -119,6 +120,8 @@ bytes(FILE *fp, off_t off)
if (len)
WR(sp, len);
}
+
+ free(sp);
return 0;
}
@@ -140,7 +143,7 @@ lines(FILE *fp, off_t off)
u_int len;
char *l;
} *llines;
- int ch;
+ int ch, rc;
char *p, *sp;
int blen, cnt, recno, wrap;
@@ -149,6 +152,7 @@ lines(FILE *fp, off_t off)
bzero(llines, off * sizeof(*llines));
sp = NULL;
blen = cnt = recno = wrap = 0;
+ rc = 0;
while ((ch = getc(fp)) != EOF) {
if (++cnt > blen) {
@@ -175,7 +179,8 @@ lines(FILE *fp, off_t off)
}
if (ferror(fp)) {
ierr();
- return 1;
+ rc = 1;
+ goto done;
}
if (cnt) {
llines[recno].l = sp;
@@ -199,5 +204,10 @@ lines(FILE *fp, off_t off)
for (cnt = 0; cnt < recno; ++cnt)
WR(llines[cnt].l, llines[cnt].len);
}
- return 0;
+done:
+ for (cnt = 0; cnt < off; cnt++)
+ free(llines[cnt].l);
+ free(sp);
+ free(llines);
+ return (rc);
}