aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorzhanghailiang <zhang.zhanghailiang@huawei.com>2015-09-14 18:40:10 +0800
committerMichael S. Tsirkin <mst@redhat.com>2015-10-22 14:34:50 +0300
commite3fce97cf500c61f23df8e0245e08625fc375295 (patch)
tree8d7c73804c14ff01d21a12730e7a27bb8b286096 /hw
parentf8d82b8eb81d3ea29325b4046fafa8ed41e32449 (diff)
downloadqemu-e3fce97cf500c61f23df8e0245e08625fc375295.zip
qemu-e3fce97cf500c61f23df8e0245e08625fc375295.tar.gz
qemu-e3fce97cf500c61f23df8e0245e08625fc375295.tar.bz2
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>
Diffstat (limited to 'hw')
-rw-r--r--hw/pci-host/piix.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 1fb71c8..7b2fbf9 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -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;
@@ -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)