[libvirt] [PATCH 0/2] Fix lxc callers using virDomainObjListRemove

Details in each patch - being consistent for future adjustment. John Ferlan (2): lxc: Fix possible leaked @vm in lxcDomainCreateXMLWithFiles lxc: Fix object locking after virDomainObjListRemove src/lxc/lxc_driver.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) -- 2.13.6

In error paths, if we call virDomainObjListRemove we will leak the @vm because we have called with a reffed and locked @vm. So rather than set it to NULL, relock the @vm and allow the virDomainObjEndAPI to perform the magic of Unlock/Unref. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/lxc/lxc_driver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 4f600f3df7..54f853cbae 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1245,7 +1245,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn, if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0) { if (!vm->persistent) { virDomainObjListRemove(driver->domains, vm); - vm = NULL; + virObjectLock(vm); } goto cleanup; } @@ -1258,7 +1258,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn, virLXCDomainObjEndJob(driver, vm); if (!vm->persistent) { virDomainObjListRemove(driver->domains, vm); - vm = NULL; + virObjectLock(vm); } goto cleanup; } -- 2.13.6

The virDomainObjListRemove will return an unlocked @vm after calling with a reffed object, thus prior to calling virDomainObjEndAPI we should relock. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/lxc/lxc_driver.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 54f853cbae..9cf67b9854 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -493,6 +493,7 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) if (virDomainSaveConfig(cfg->configDir, driver->caps, vm->newDef ? vm->newDef : vm->def) < 0) { virDomainObjListRemove(driver->domains, vm); + virObjectLock(vm); goto cleanup; } @@ -557,6 +558,7 @@ static int lxcDomainUndefineFlags(virDomainPtr dom, vm->persistent = 0; } else { virDomainObjListRemove(driver->domains, vm); + virObjectLock(vm); } ret = 0; @@ -1529,8 +1531,10 @@ lxcDomainDestroyFlags(virDomainPtr dom, endjob: virLXCDomainObjEndJob(driver, vm); - if (!vm->persistent) + if (!vm->persistent) { virDomainObjListRemove(driver->domains, vm); + virObjectLock(vm); + } cleanup: virDomainObjEndAPI(&vm); -- 2.13.6

ping? Tks, John On 04/02/2018 10:15 AM, John Ferlan wrote:
Details in each patch - being consistent for future adjustment.
John Ferlan (2): lxc: Fix possible leaked @vm in lxcDomainCreateXMLWithFiles lxc: Fix object locking after virDomainObjListRemove
src/lxc/lxc_driver.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)

ping? Tks, John On 04/02/2018 10:15 AM, John Ferlan wrote:
Details in each patch - being consistent for future adjustment.
John Ferlan (2): lxc: Fix possible leaked @vm in lxcDomainCreateXMLWithFiles lxc: Fix object locking after virDomainObjListRemove
src/lxc/lxc_driver.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)

On 04/02/2018 04:15 PM, John Ferlan wrote:
Details in each patch - being consistent for future adjustment.
John Ferlan (2): lxc: Fix possible leaked @vm in lxcDomainCreateXMLWithFiles lxc: Fix object locking after virDomainObjListRemove
src/lxc/lxc_driver.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
ACK to both. Michal
participants (2)
-
John Ferlan
-
Michal Privoznik