From f2a6c2d39d1f898e6a1571b8834c30feb860fc26 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 9 Sep 2025 17:18:34 +0200 Subject: [PATCH] ch: Avoid memleak on disk detach in chDomainRemoveDevice() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- src/ch/ch_hotplug.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ch/ch_hotplug.c b/src/ch/ch_hotplug.c index cfa11cc5e5..0a55a57069 100644 --- a/src/ch/ch_hotplug.c +++ b/src/ch/ch_hotplug.c @@ -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; } } -- 2.47.3