[PATCH v2 01/12] conf: Introduce virDomainInputDefRemove and fix memory leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Luke Yue <lukedyue@xxxxxxxxx>
---
 src/conf/domain_conf.c   | 12 ++++++++++++
 src/conf/domain_conf.h   |  2 ++
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_driver.c   |  3 ++-
 4 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 10effdce69..6667426b9a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16760,6 +16760,18 @@ virDomainInputDefFind(const virDomainDef *def,
 }
 
 
+virDomainInputDef *
+virDomainInputDefRemove(virDomainDef *def,
+                        size_t idx)
+{
+    virDomainInputDef *ret = def->inputs[idx];
+
+    VIR_DELETE_ELEMENT(def->inputs, idx, def->ninputs);
+
+    return ret;
+}
+
+
 bool
 virDomainVsockDefEquals(const virDomainVsockDef *a,
                         const virDomainVsockDef *b)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c7e6df7981..3e4701176d 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3815,6 +3815,8 @@ virDomainShmemDef *virDomainShmemDefRemove(virDomainDef *def, size_t idx)
 ssize_t virDomainInputDefFind(const virDomainDef *def,
                               const virDomainInputDef *input)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
+virDomainInputDef *virDomainInputDefRemove(virDomainDef *def, size_t idx)
+    ATTRIBUTE_NONNULL(1);
 bool virDomainVsockDefEquals(const virDomainVsockDef *a,
                              const virDomainVsockDef *b)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 090ac80691..f74291cb06 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -476,6 +476,7 @@ virDomainInputBusTypeToString;
 virDomainInputDefFind;
 virDomainInputDefFree;
 virDomainInputDefGetPath;
+virDomainInputDefRemove;
 virDomainInputSourceGrabToggleTypeFromString;
 virDomainInputSourceGrabToggleTypeToString;
 virDomainInputSourceGrabTypeFromString;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f31e13889e..c008921582 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7569,7 +7569,8 @@ qemuDomainDetachDeviceConfig(virDomainDef *vmdef,
                            _("matching input device not found"));
             return -1;
         }
-        VIR_DELETE_ELEMENT(vmdef->inputs, idx, vmdef->ninputs);
+
+        virDomainInputDefFree(virDomainInputDefRemove(vmdef, idx));
         break;
 
     case VIR_DOMAIN_DEVICE_VSOCK:
-- 
2.33.0




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux