From: Daniel P. Berrange Date: Thu, 20 Feb 2014 15:32:49 +0000 (+0000) Subject: Fix multiple bugs in LXC domainMemoryStats driver X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=cb9b3bc25765f586df029d6ea867313ad73d450d;p=libvirt.git Fix multiple bugs in LXC domainMemoryStats driver The virCgroupXXX APIs' return value must be checked for being less than 0, not equal to 0. An VIR_ERR_OPERATION_INVALID error must also be raised when the VM is not running to prevent a crash on NULL priv->cgroup field. Signed-off-by: Daniel P. Berrange --- diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 50910df4df..10e0fbbefe 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -5410,13 +5410,16 @@ lxcDomainMemoryStats(virDomainPtr dom, if (virDomainMemoryStatsEnsureACL(dom->conn, vm->def) < 0) goto cleanup; - if (!virCgroupGetMemSwapUsage(priv->cgroup, &swap_usage)) + if (!virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("domain is not active")); goto cleanup; + } - if (!virCgroupGetMemoryUsage(priv->cgroup, &mem_usage)) + if (virCgroupGetMemSwapUsage(priv->cgroup, &swap_usage) < 0) goto cleanup; - if (!virDomainObjIsActive(vm)) + if (virCgroupGetMemoryUsage(priv->cgroup, &mem_usage) < 0) goto cleanup; ret = 0;