]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
Fix file descriptor leak in HASHFileChunk helper
authorGuillem Jover <guillem@hadrons.org>
Sun, 7 Feb 2016 01:53:28 +0000 (02:53 +0100)
committerGuillem Jover <guillem@hadrons.org>
Sun, 7 Feb 2016 08:17:08 +0000 (09:17 +0100)
This leak only happens on error conditions, so it's not too bad.

Warned-by: coverity
src/hash/helper.c

index 06af1892050c70fd31c33eb1e71cced20823c3d1..1c63564f737b7e6d63c3b213a0bb516503c977b4 100644 (file)
@@ -67,8 +67,10 @@ HASHFileChunk(const char *filename, char *buf, off_t off, off_t len)
                }
                len = sb.st_size;
        }
-       if ((len < 0) || (off > 0 && lseek(fd, off, SEEK_SET) < 0))
+       if ((len < 0) || (off > 0 && lseek(fd, off, SEEK_SET) < 0)) {
+               close(fd);
                return (NULL);
+       }
 
        while ((nr = read(fd, buffer,
            (size_t)(len ? MIN(BUFSIZ, len) : BUFSIZ))) > 0) {