Fix file descriptor leak in HASHFileChunk helper

This leak only happens on error conditions, so it's not too bad.

Warned-by: coverity
This commit is contained in:
Guillem Jover 2016-02-07 02:53:28 +01:00
parent 5a32ea0a72
commit cbe3057703

View File

@ -67,8 +67,10 @@ HASHFileChunk(const char *filename, char *buf, off_t off, off_t len)
} }
len = sb.st_size; 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); return (NULL);
}
while ((nr = read(fd, buffer, while ((nr = read(fd, buffer,
(size_t)(len ? MIN(BUFSIZ, len) : BUFSIZ))) > 0) { (size_t)(len ? MIN(BUFSIZ, len) : BUFSIZ))) > 0) {