]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commit
util: eliminate device object leaks related to virDomain*Remove*()
authorLaine Stump <laine@laine.org>
Tue, 6 Mar 2012 23:06:14 +0000 (18:06 -0500)
committerLaine Stump <laine@laine.org>
Thu, 8 Mar 2012 21:58:27 +0000 (16:58 -0500)
commitf985773d06ed17cd699907ac8b271864c8b67870
tree2e18b306bc80c904cda4b5f66af86074ff6f47e3
parentb59e59845f4ba59c68e17cbd0e41954bec75d333
util: eliminate device object leaks related to virDomain*Remove*()

There are several functions in domain_conf.c that remove a device
object from the domain's list of that object type, but don't free the
object or return it to the caller to free. In many cases this isn't a
problem because the caller already had a pointer to the object and
frees it afterward, but in several cases the removed object was just
left floating around with no references to it.

In particular, the function qemuDomainDetachDeviceConfig() calls
functions to locate and remove net (virDomainNetRemoveByMac), disk
(virDomainDiskRemoveByName()), and lease (virDomainLeaseRemove())
devices, but neither it nor its caller qemuDomainModifyDeviceConfig()
ever obtain a pointer to the device being removed, much less free it.

This patch modifies the following "remove" functions to return a
pointer to the device object being removed from the domain device
arrays, to give the caller the option of freeing the device object
using that pointer if needed. In places where the object was
previously leaked, it is now freed:

  virDomainDiskRemove
  virDomainDiskRemoveByName
  virDomainNetRemove
  virDomainNetRemoveByMac
  virDomainHostdevRemove
  virDomainLeaseRemove
  virDomainLeaseRemoveAt

The functions that had been leaking:

  libxlDomainDetachConfig - leaked a virDomainDiskDef
  qemuDomainDetachDeviceConfig - could leak a virDomainDiskDef,
                            a virDomainNetDef, or a
                            virDomainLeaseDef
  qemuDomainDetachLease   - leaked a virDomainLeaseDef
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libxl/libxl_driver.c
src/qemu/qemu_driver.c
src/qemu/qemu_hotplug.c