vfio/pci: fix potential memory leak in vfio_intx_enable()
authorYe Bin <yebin10@huawei.com>
Mon, 15 Apr 2024 01:50:29 +0000 (09:50 +0800)
committerAlex Williamson <alex.williamson@redhat.com>
Mon, 22 Apr 2024 22:52:08 +0000 (16:52 -0600)
If vfio_irq_ctx_alloc() failed will lead to 'name' memory leak.

Fixes: 18c198c96a81 ("vfio/pci: Create persistent INTx handler")
Signed-off-by: Ye Bin <yebin10@huawei.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Acked-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://lore.kernel.org/r/20240415015029.3699844-1-yebin10@huawei.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/pci/vfio_pci_intrs.c

index d52825a096ad9f4d7025d5c8ceb91aa88b6d98cc..8382c583433565f9cecbed9fefbd0cbbcbcc809f 100644 (file)
@@ -267,8 +267,10 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev,
                return -ENOMEM;
 
        ctx = vfio_irq_ctx_alloc(vdev, 0);
-       if (!ctx)
+       if (!ctx) {
+               kfree(name);
                return -ENOMEM;
+       }
 
        ctx->name = name;
        ctx->trigger = trigger;