svn commit: r311340 - head/usr.bin/tail
Alan Somers
asomers at FreeBSD.org
Wed Jan 4 23:22:35 UTC 2017
Author: asomers
Date: Wed Jan 4 23:22:34 2017
New Revision: 311340
URL: https://svnweb.freebsd.org/changeset/base/311340
Log:
Misc Coverity fixes for tail(1)
CID 1006402: Initialize stack variable
CID 271580: Don't leak memory when ENOMEM.
Reported by: Coverity
CID: 271580 1006402
MFC after: 4 weeks
Sponsored by: Spectra Logic Corp
Modified:
head/usr.bin/tail/reverse.c
Modified: head/usr.bin/tail/reverse.c
==============================================================================
--- head/usr.bin/tail/reverse.c Wed Jan 4 22:32:17 2017 (r311339)
+++ head/usr.bin/tail/reverse.c Wed Jan 4 23:22:34 2017 (r311340)
@@ -117,6 +117,7 @@ r_reg(FILE *fp, const char *fn, enum STY
map.start = NULL;
map.mapoff = map.maxoff = size;
map.fd = fileno(fp);
+ map.maplen = 0;
/*
* Last char is special, ignore whether newline or not. Note that
@@ -205,7 +206,13 @@ r_buf(FILE *fp, const char *fn)
(tl->l = malloc(BSZ)) == NULL) {
if (!mark)
err(1, "malloc");
- tl = enomem ? tl->next : mark;
+ if (enomem)
+ tl = tl->next;
+ else {
+ if (tl)
+ free(tl);
+ tl = mark;
+ }
enomem += tl->len;
} else if (mark) {
tl->next = mark;
More information about the svn-src-head
mailing list