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;
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to