Author: jtl
Date: Wed Dec 30 18:04:50 2015
New Revision: 292955
URL: https://svnweb.freebsd.org/changeset/base/292955

Log:
  Fix a file descriptor leak in mdXhl.c (which is used by numerous hashing
  algorithms.
  
  CID:  1305669,1305611,1305663,1305603,1305584,1305639,1346865,1305601
  Differential Revision:        https://reviews.freebsd.org/D4732
  Reviewed by:  allanjude, delphij
  MFC after:    2 weeks
  Sponsored by: Juniper Networks

Modified:
  head/lib/libmd/mdXhl.c

Modified: head/lib/libmd/mdXhl.c
==============================================================================
--- head/lib/libmd/mdXhl.c      Wed Dec 30 17:36:34 2015        (r292954)
+++ head/lib/libmd/mdXhl.c      Wed Dec 30 18:04:50 2015        (r292955)
@@ -59,14 +59,18 @@ MDXFileChunk(const char *filename, char 
        f = open(filename, O_RDONLY);
        if (f < 0)
                return 0;
-       if (fstat(f, &stbuf) < 0)
-               return 0;
+       if (fstat(f, &stbuf) < 0) {
+               i = -1;
+               goto error;
+       }
        if (ofs > stbuf.st_size)
                ofs = stbuf.st_size;
        if ((len == 0) || (len > stbuf.st_size - ofs))
                len = stbuf.st_size - ofs;
-       if (lseek(f, ofs, SEEK_SET) < 0)
-               return 0;
+       if (lseek(f, ofs, SEEK_SET) < 0) {
+               i = -1;
+               goto error;
+       }
        n = len;
        i = 0;
        while (n > 0) {
@@ -79,6 +83,7 @@ MDXFileChunk(const char *filename, char 
                MDXUpdate(&ctx, buffer, i);
                n -= i;
        } 
+error:
        e = errno;
        close(f);
        errno = e;
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to