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

[libvirt] [PATCH 3/3] virQEMUDriverGetConfig: Fix memleak



==19015== 968 (416 direct, 552 indirect) bytes in 1 blocks are definitely lost in loss record 999 of 1,049
==19015==    at 0x4C2C070: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==19015==    by 0x52ADF14: virAllocVar (viralloc.c:560)
==19015==    by 0x5302FD1: virObjectNew (virobject.c:193)
==19015==    by 0x1DD9401E: virQEMUDriverConfigNew (qemu_conf.c:164)
==19015==    by 0x1DDDF65D: qemuStateInitialize (qemu_driver.c:666)
==19015==    by 0x53E0823: virStateInitialize (libvirt.c:777)
==19015==    by 0x11E067: daemonRunStateInit (libvirtd.c:905)
==19015==    by 0x53201AD: virThreadHelper (virthread.c:206)
==19015==    by 0xA1EE1F2: start_thread (in /lib64/libpthread-2.19.so)
==19015==    by 0xA4EFC8C: clone (in /lib64/libc-2.19.so)

Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 src/qemu/qemu_cgroup.c  |  4 +++-
 src/qemu/qemu_command.c |  5 ++++-
 src/qemu/qemu_domain.c  | 58 +++++++++++++++++++++++--------------------------
 3 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index e32cd31..7d64ce7 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -1246,11 +1246,13 @@ qemuRemoveCgroup(virQEMUDriverPtr driver,
                  virDomainObjPtr vm)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    virQEMUDriverConfigPtr cfg;
 
     if (priv->cgroup == NULL)
         return 0; /* Not supported, so claim success */
 
+    cfg = virQEMUDriverGetConfig(driver);
+
     if (virCgroupTerminateMachine(vm->def->name,
                                   "qemu",
                                   cfg->privileged) < 0) {
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index e94caea..3f0df58 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8051,7 +8051,7 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
     char **tapfdName = NULL;
     char **vhostfdName = NULL;
     int actualType = virDomainNetGetActualType(net);
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    virQEMUDriverConfigPtr cfg = NULL;
     virNetDevBandwidthPtr actualBandwidth;
     size_t i;
 
@@ -8088,6 +8088,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
         return -1;
     }
 
+    cfg = virQEMUDriverGetConfig(driver);
+
     if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
         actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
         tapfdSize = net->driver.virtio.queues;
@@ -8269,6 +8271,7 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
     VIR_FREE(host);
     VIR_FREE(tapfdName);
     VIR_FREE(vhostfdName);
+    virObjectUnref(cfg);
     return ret;
 }
 
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 786e0b8..ba6a1ba 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1093,7 +1093,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 {
     int ret = -1;
     virQEMUDriverPtr driver = opaque;
-    virQEMUDriverConfigPtr cfg = NULL;
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
 
     if (dev->type == VIR_DOMAIN_DEVICE_NET &&
         dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
@@ -1107,37 +1107,34 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
     if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
         virDomainDiskDefPtr disk = dev->data.disk;
 
-        /* both of these require data from the driver config */
-        if (driver && (cfg = virQEMUDriverGetConfig(driver))) {
-            /* assign default storage format and driver according to config */
-            if (cfg->allowDiskFormatProbing) {
-                /* default disk format for drives */
-                if (virDomainDiskGetFormat(disk) == VIR_STORAGE_FILE_NONE &&
-                    (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_FILE ||
-                     virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_BLOCK))
-                    virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_AUTO);
+        /* assign default storage format and driver according to config */
+        if (cfg->allowDiskFormatProbing) {
+            /* default disk format for drives */
+            if (virDomainDiskGetFormat(disk) == VIR_STORAGE_FILE_NONE &&
+                (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_FILE ||
+                 virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_BLOCK))
+                virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_AUTO);
 
-                 /* default disk format for mirrored drive */
-                if (disk->mirror &&
-                    disk->mirror->format == VIR_STORAGE_FILE_NONE)
-                    disk->mirror->format = VIR_STORAGE_FILE_AUTO;
-            } else {
-                /* default driver if probing is forbidden */
-                if (!virDomainDiskGetDriver(disk) &&
-                    virDomainDiskSetDriver(disk, "qemu") < 0)
-                        goto cleanup;
+            /* default disk format for mirrored drive */
+            if (disk->mirror &&
+                disk->mirror->format == VIR_STORAGE_FILE_NONE)
+                disk->mirror->format = VIR_STORAGE_FILE_AUTO;
+        } else {
+            /* default driver if probing is forbidden */
+            if (!virDomainDiskGetDriver(disk) &&
+                virDomainDiskSetDriver(disk, "qemu") < 0)
+                goto cleanup;
 
-                /* default disk format for drives */
-                if (virDomainDiskGetFormat(disk) == VIR_STORAGE_FILE_NONE &&
-                    (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_FILE ||
-                     virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_BLOCK))
-                    virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW);
+            /* default disk format for drives */
+            if (virDomainDiskGetFormat(disk) == VIR_STORAGE_FILE_NONE &&
+                (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_FILE ||
+                 virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_BLOCK))
+                virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW);
 
-                 /* default disk format for mirrored drive */
-                if (disk->mirror &&
-                    disk->mirror->format == VIR_STORAGE_FILE_NONE)
-                    disk->mirror->format = VIR_STORAGE_FILE_RAW;
-            }
+            /* default disk format for mirrored drive */
+            if (disk->mirror &&
+                disk->mirror->format == VIR_STORAGE_FILE_NONE)
+                disk->mirror->format = VIR_STORAGE_FILE_RAW;
         }
     }
 
@@ -1168,8 +1165,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
         dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
         dev->data.chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO &&
         dev->data.chr->source.type == VIR_DOMAIN_CHR_TYPE_UNIX &&
-        !dev->data.chr->source.data.nix.path &&
-        (driver && (cfg = virQEMUDriverGetConfig(driver)))) {
+        !dev->data.chr->source.data.nix.path) {
 
         if (virAsprintf(&dev->data.chr->source.data.nix.path,
                         "%s/channel/target/%s.%s",
-- 
2.0.5


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