From cb9b3bc25765f586df029d6ea867313ad73d450d Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Thu, 20 Feb 2014 15:32:49 +0000 Subject: [PATCH] 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 --- src/lxc/lxc_driver.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 (virCgroupGetMemSwapUsage(priv->cgroup, &swap_usage) < 0) goto cleanup; - if (!virCgroupGetMemoryUsage(priv->cgroup, &mem_usage)) - goto cleanup; - - if (!virDomainObjIsActive(vm)) + if (virCgroupGetMemoryUsage(priv->cgroup, &mem_usage) < 0) goto cleanup; ret = 0;