If virCommandPassFD() is called with VIR_COMMAND_PASS_FD_CLOSE_PARENT the passed FD is closed. If qemuVirCommandGetFDSet() returns NULL we would jump to cleanup where the vdpafd is closed again if not set to -1. In order to fix it use a different variable where we will copy FD number. Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx> --- src/qemu/qemu_command.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 0eec35da16..2a786e34dd 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8141,18 +8141,20 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, if (vdpafd > 0) { g_autofree char *fdset = NULL; g_autofree char *addfdarg = NULL; + int vdpafd_copy = vdpafd; virCommandPassFD(cmd, vdpafd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); - fdset = qemuVirCommandGetFDSet(cmd, vdpafd); + vdpafd = -1; + + fdset = qemuVirCommandGetFDSet(cmd, vdpafd_copy); if (!fdset) goto cleanup; - vdpafdName = qemuVirCommandGetDevSet(cmd, vdpafd); + vdpafdName = qemuVirCommandGetDevSet(cmd, vdpafd_copy); /* set opaque to the devicepath so that we can look up the fdset later * if necessary */ addfdarg = g_strdup_printf("%s,opaque=%s", fdset, net->data.vdpa.devicepath); virCommandAddArgList(cmd, "-add-fd", addfdarg, NULL); - vdpafd = -1; } if (chardev) -- 2.26.2