fix memory/fd leak in pt_msix_init()
Signed-off-by: Isaku Yamahata <yamahata@xxxxxxxxxxxxx>
---
hw/pass-through.h | 1 -
hw/pt-msi.c | 19 ++++++++++++++++---
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/hw/pass-through.h b/hw/pass-through.h
index 7a623be..6943b4b 100644
--- a/hw/pass-through.h
+++ b/hw/pass-through.h
@@ -142,7 +142,6 @@ struct pt_msix_info {
uint32_t table_off;
uint64_t mmio_base_addr;
int mmio_index;
- int fd;
void *phys_iomem_base;
struct msix_entry_info msix_entry[0];
};
diff --git a/hw/pt-msi.c b/hw/pt-msi.c
index 5039d64..519126d 100644
--- a/hw/pt-msi.c
+++ b/hw/pt-msi.c
@@ -283,6 +283,7 @@ int pt_msix_init(struct pt_dev *dev, int pos)
uint16_t control;
int i, total_entries, table_off, bar_index;
struct pci_dev *pd = dev->pci_dev;
+ int fd;
id = pci_read_byte(pd, pos + PCI_CAP_LIST_ID);
@@ -319,19 +320,31 @@ int pt_msix_init(struct pt_dev *dev, int pos)
PT_LOG("get MSI-X table bar base %llx\n",
(unsigned long long)dev->msix->table_base);
- dev->msix->fd = open("/dev/mem", O_RDWR);
+ fd = open("/dev/mem", O_RDWR);
+ if ( fd == -1 )
+ {
+ PT_LOG("Can't open /dev/mem: %s\n", strerror(errno));
+ goto error_out;
+ }
dev->msix->phys_iomem_base = mmap(0, total_entries * 16,
PROT_WRITE | PROT_READ, MAP_SHARED | MAP_LOCKED,
- dev->msix->fd, dev->msix->table_base + table_off);
+ fd, dev->msix->table_base + table_off);
if ( dev->msix->phys_iomem_base == MAP_FAILED )
{
PT_LOG("Can't map physical MSI-X table: %s\n", strerror(errno));
- return -1;
+ close(fd);
+ goto error_out;
}
+ close(fd);
PT_LOG("mapping physical MSI-X table to %lx\n",
(unsigned long)dev->msix->phys_iomem_base);
return 0;
+
+error_out:
+ free(dev->msix);
+ dev->msix = NULL;
+ return -1;
}
void pt_msix_delete(struct pt_dev *dev)
--
1.6.0.2
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|