mirror of https://github.com/xemu-project/xemu.git
piix: fix resource leak reported by Coverity
config_fd should be closed before return, or there will be a resource leak error. Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
f8d82b8eb8
commit
e3fce97cf5
|
@ -764,6 +764,7 @@ static int host_pci_config_read(int pos, int len, uint32_t val)
|
||||||
/* Access real host bridge. */
|
/* Access real host bridge. */
|
||||||
int rc = snprintf(path, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s",
|
int rc = snprintf(path, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s",
|
||||||
0, 0, 0, 0, "config");
|
0, 0, 0, 0, "config");
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
if (rc >= size || rc < 0) {
|
if (rc >= size || rc < 0) {
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
@ -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) {
|
if (lseek(config_fd, pos, SEEK_SET) != pos) {
|
||||||
return -errno;
|
ret = -errno;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
rc = read(config_fd, (uint8_t *)&val, len);
|
rc = read(config_fd, (uint8_t *)&val, len);
|
||||||
} while (rc < 0 && (errno == EINTR || errno == EAGAIN));
|
} while (rc < 0 && (errno == EINTR || errno == EAGAIN));
|
||||||
if (rc != len) {
|
if (rc != len) {
|
||||||
return -errno;
|
ret = -errno;
|
||||||
}
|
}
|
||||||
|
out:
|
||||||
return 0;
|
close(config_fd);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev)
|
static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev)
|
||||||
|
|
Loading…
Reference in New Issue