WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] ioemu: fix memory/fd leak in pt_msix_init()

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] ioemu: fix memory/fd leak in pt_msix_init()
From: Isaku Yamahata <yamahata@xxxxxxxxxxxxx>
Date: Mon, 9 Feb 2009 18:09:58 +0900
Cc: Ian.Jackson@xxxxxxxxxxxxx
Delivery-date: Mon, 09 Feb 2009 01:10:23 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.6i
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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] ioemu: fix memory/fd leak in pt_msix_init(), Isaku Yamahata <=