From d7cc2520f23cad545275f90364d2c18f15d6e2f0 Mon Sep 17 00:00:00 2001 From: Alex Jia Date: Wed, 30 Nov 2011 13:57:10 +0800 Subject: [PATCH] uml: Plug memory leak on umlStartVMDaemon() error path Detected by Coverity. Leak introduced in commit 8866eed. Two bugs here: 1. logfd wasn't closed on all return paths 2. if we failed to mark a domain autodestroy, then the domain was not made transient but we still returned success Signed-off-by: Alex Jia Signed-off-by: Eric Blake --- src/uml/uml_driver.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 073f3620de..faea313f6d 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1040,12 +1040,8 @@ static int umlStartVMDaemon(virConnectPtr conn, return -1; } - if (!(cmd = umlBuildCommandLine(conn, driver, vm))) { - VIR_FORCE_CLOSE(logfd); - virDomainConfVMNWFilterTeardown(vm); - umlCleanupTapDevices(vm); - return -1; - } + if (!(cmd = umlBuildCommandLine(conn, driver, vm))) + goto cleanup; for (i = 0 ; i < vm->def->nconsoles ; i++) { VIR_FREE(vm->def->consoles[i]->info.alias); @@ -1065,16 +1061,16 @@ static int umlStartVMDaemon(virConnectPtr conn, virCommandDaemonize(cmd); ret = virCommandRun(cmd, NULL); - VIR_FORCE_CLOSE(logfd); if (ret < 0) goto cleanup; if (autoDestroy && - umlProcessAutoDestroyAdd(driver, vm, conn) < 0) + (ret = umlProcessAutoDestroyAdd(driver, vm, conn)) < 0) goto cleanup; ret = virDomainObjSetDefTransient(driver->caps, vm, false); cleanup: + VIR_FORCE_CLOSE(logfd); virCommandFree(cmd); if (ret < 0) {