Skip to content

Commit

Permalink
piix: fix resource leak reported by Coverity
Browse files Browse the repository at this point in the history
config_fd should be closed before return, or there will
be a resource leak error.

Signed-off-by: zhanghailiang <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
colo-ft authored and mstsirkin committed Oct 22, 2015
1 parent f8d82b8 commit e3fce97
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions hw/pci-host/piix.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ static int host_pci_config_read(int pos, int len, uint32_t val)
/* Access real host bridge. */
int rc = snprintf(path, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s",
0, 0, 0, 0, "config");
int ret = 0;

if (rc >= size || rc < 0) {
return -ENODEV;
Expand All @@ -775,16 +776,18 @@ static int host_pci_config_read(int pos, int len, uint32_t val)
}

if (lseek(config_fd, pos, SEEK_SET) != pos) {
return -errno;
ret = -errno;
goto out;
}
do {
rc = read(config_fd, (uint8_t *)&val, len);
} while (rc < 0 && (errno == EINTR || errno == EAGAIN));
if (rc != len) {
return -errno;
ret = -errno;
}

return 0;
out:
close(config_fd);
return ret;
}

static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev)
Expand Down

0 comments on commit e3fce97

Please sign in to comment.