Fix Coverity Scan CID
1521069 reporting leaking fd on read error.
Refactor the read error handling and correctly close fd on read error.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
long res = -1;
TSTM((fd = open(path, O_RDONLY)) >= 0, -1, "%m");
int l;
- TSTM((l = read(fd, buf, sizeof(buf) - 1)) >= 0, -1, "%m");
+ if((l = read(fd, buf, sizeof(buf) - 1)) < 0) {
+ ERROR("Failed to read file %s: error %m", file);
+ return -1;
+ }
if(0 == l)
{
ERROR("Empty %s file", file);