[libvirt PATCH] iommufd: fix FD leak in case of error

Pavel Hrdina via Devel posted 1 patch 1 week, 6 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/7a78d6bebcd642bd31ca23e48dbb1abcf7f1fcf1.1771315738.git.phrdina@redhat.com
src/util/viriommufd.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[libvirt PATCH] iommufd: fix FD leak in case of error
Posted by Pavel Hrdina via Devel 1 week, 6 days ago
Reported-by: coverity
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/util/viriommufd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/util/viriommufd.c b/src/util/viriommufd.c
index 1f3353eab4..b62d59241d 100644
--- a/src/util/viriommufd.c
+++ b/src/util/viriommufd.c
@@ -87,8 +87,10 @@ virIOMMUFDOpenDevice(void)
     if ((fd = open(VIR_IOMMU_DEV_PATH, O_RDWR | O_CLOEXEC)) < 0)
         virReportSystemError(errno, "%s", _("cannot open IOMMUFD device"));
 
-    if (virIOMMUFDSetRLimitMode(fd, true) < 0)
+    if (virIOMMUFDSetRLimitMode(fd, true) < 0) {
+        VIR_FORCE_CLOSE(fd);
         return -1;
+    }
 
     return fd;
 }
-- 
2.53.0
Re: [libvirt PATCH] iommufd: fix FD leak in case of error
Posted by Ján Tomko via Devel 1 week, 6 days ago
On a Tuesday in 2026, Pavel Hrdina via Devel wrote:
>Reported-by: coverity
>Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
>---
> src/util/viriommufd.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
>diff --git a/src/util/viriommufd.c b/src/util/viriommufd.c
>index 1f3353eab4..b62d59241d 100644
>--- a/src/util/viriommufd.c
>+++ b/src/util/viriommufd.c
>@@ -87,8 +87,10 @@ virIOMMUFDOpenDevice(void)
>     if ((fd = open(VIR_IOMMU_DEV_PATH, O_RDWR | O_CLOEXEC)) < 0)
>         virReportSystemError(errno, "%s", _("cannot open IOMMUFD device"));
>
>-    if (virIOMMUFDSetRLimitMode(fd, true) < 0)
>+    if (virIOMMUFDSetRLimitMode(fd, true) < 0) {
>+        VIR_FORCE_CLOSE(fd);
>         return -1;
>+    }
>
>     return fd;
> }
>-- 

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano