]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch: Avoid memleak on disk detach in chDomainRemoveDevice()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 9 Sep 2025 15:18:34 +0000 (17:18 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 10 Sep 2025 09:45:07 +0000 (11:45 +0200)
The aim of chDomainRemoveDevice() is to remove device from
virDomainDef. Well, in case of disks this is done by calling
virDomainDiskRemove() which merely just removes it from the array
of virDomainDiskDef-s but leaves it up to the caller to actually
free the disk def.

1,286 (560 direct, 726 indirect) bytes in 1 blocks are definitely lost in loss record 2,005 of 2,041
   at 0x4919EF3: calloc (vg_replace_malloc.c:1675)
   by 0x4FEB249: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.8400.3)
   by 0x4AFD9A4: virDomainDiskDefNewSource (domain_conf.c:2409)
   by 0x4B10ACA: virDomainDiskDefParseXML (domain_conf.c:8509)
   by 0x4B24F07: virDomainDeviceDefParse (domain_conf.c:14631)
   by 0xB8D8881: chDomainAttachDeviceLiveAndUpdateConfig (ch_hotplug.c:135)
   by 0xB8CCFE0: chDomainAttachDeviceFlags (ch_driver.c:2376)
   by 0xB8CD057: chDomainAttachDevice (ch_driver.c:2394)
   by 0x4DC1C7D: virDomainAttachDevice (libvirt-domain.c:8951)
   by 0x405E545: remoteDispatchDomainAttachDevice (remote_daemon_dispatch_stubs.h:3763)
   by 0x405E495: remoteDispatchDomainAttachDeviceHelper (remote_daemon_dispatch_stubs.h:3742)
   by 0x4BF3164: virNetServerProgramDispatchCall (virnetserverprogram.c:423)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/ch/ch_hotplug.c

index cfa11cc5e58086042b0c194b9574b739bcfd615f..0a55a5706902cf232e3a620d580e26823718b69e 100644 (file)
@@ -212,6 +212,7 @@ chDomainRemoveDevice(virDomainObj *vm,
         for (i = 0; i < vm->def->ndisks; i++) {
             if (vm->def->disks[i] == device->data.disk) {
                 virDomainDiskRemove(vm->def, i);
+                g_clear_pointer(&device->data.disk, virDomainDiskDefFree);
                 break;
             }
         }