提交 996f1014 编写于 作者: J John Ferlan

lxc: Resolve memory leak

Commit 40b5c99a modified the virConfGetValue callers to use
virConfGetValueString. However, using the virConfGetValueString
resulted in leaking the returned @value string in each case.
So, let's modify each instance to use the VIR_AUTOFREE(char *)
syntax. In some instances changing the variable name since
@value was used more than once.

Found by Coverity
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 f6399b9d
...@@ -198,7 +198,7 @@ lxcSetRootfs(virDomainDefPtr def, ...@@ -198,7 +198,7 @@ lxcSetRootfs(virDomainDefPtr def,
virConfPtr properties) virConfPtr properties)
{ {
int type = VIR_DOMAIN_FS_TYPE_MOUNT; int type = VIR_DOMAIN_FS_TYPE_MOUNT;
char *value = NULL; VIR_AUTOFREE(char *) value = NULL;
if (virConfGetValueString(properties, "lxc.rootfs", &value) <= 0) if (virConfGetValueString(properties, "lxc.rootfs", &value) <= 0)
return -1; return -1;
...@@ -679,7 +679,7 @@ lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties) ...@@ -679,7 +679,7 @@ lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties)
static int static int
lxcCreateConsoles(virDomainDefPtr def, virConfPtr properties) lxcCreateConsoles(virDomainDefPtr def, virConfPtr properties)
{ {
char *value = NULL; VIR_AUTOFREE(char *) value = NULL;
int nbttys = 0; int nbttys = 0;
virDomainChrDefPtr console; virDomainChrDefPtr console;
size_t i; size_t i;
...@@ -756,7 +756,7 @@ lxcIdmapWalkCallback(const char *name, virConfValuePtr value, void *data) ...@@ -756,7 +756,7 @@ lxcIdmapWalkCallback(const char *name, virConfValuePtr value, void *data)
static int static int
lxcSetMemTune(virDomainDefPtr def, virConfPtr properties) lxcSetMemTune(virDomainDefPtr def, virConfPtr properties)
{ {
char *value = NULL; VIR_AUTOFREE(char *) value = NULL;
unsigned long long size = 0; unsigned long long size = 0;
if (virConfGetValueString(properties, if (virConfGetValueString(properties,
...@@ -767,6 +767,7 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr properties) ...@@ -767,6 +767,7 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr properties)
size = size / 1024; size = size / 1024;
virDomainDefSetMemoryTotal(def, size); virDomainDefSetMemoryTotal(def, size);
def->mem.hard_limit = virMemoryLimitTruncate(size); def->mem.hard_limit = virMemoryLimitTruncate(size);
VIR_FREE(value);
} }
if (virConfGetValueString(properties, if (virConfGetValueString(properties,
...@@ -775,6 +776,7 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr properties) ...@@ -775,6 +776,7 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr properties)
if (lxcConvertSize(value, &size) < 0) if (lxcConvertSize(value, &size) < 0)
return -1; return -1;
def->mem.soft_limit = virMemoryLimitTruncate(size / 1024); def->mem.soft_limit = virMemoryLimitTruncate(size / 1024);
VIR_FREE(value);
} }
if (virConfGetValueString(properties, if (virConfGetValueString(properties,
...@@ -790,19 +792,21 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr properties) ...@@ -790,19 +792,21 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr properties)
static int static int
lxcSetCpuTune(virDomainDefPtr def, virConfPtr properties) lxcSetCpuTune(virDomainDefPtr def, virConfPtr properties)
{ {
char *value = NULL; VIR_AUTOFREE(char *) value = NULL;
if (virConfGetValueString(properties, "lxc.cgroup.cpu.shares", if (virConfGetValueString(properties, "lxc.cgroup.cpu.shares",
&value) > 0) { &value) > 0) {
if (virStrToLong_ull(value, NULL, 10, &def->cputune.shares) < 0) if (virStrToLong_ull(value, NULL, 10, &def->cputune.shares) < 0)
goto error; goto error;
def->cputune.sharesSpecified = true; def->cputune.sharesSpecified = true;
VIR_FREE(value);
} }
if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_quota_us", if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_quota_us",
&value) > 0) { &value) > 0) {
if (virStrToLong_ll(value, NULL, 10, &def->cputune.quota) < 0) if (virStrToLong_ll(value, NULL, 10, &def->cputune.quota) < 0)
goto error; goto error;
VIR_FREE(value);
} }
if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_period_us", if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_period_us",
...@@ -822,7 +826,7 @@ lxcSetCpuTune(virDomainDefPtr def, virConfPtr properties) ...@@ -822,7 +826,7 @@ lxcSetCpuTune(virDomainDefPtr def, virConfPtr properties)
static int static int
lxcSetCpusetTune(virDomainDefPtr def, virConfPtr properties) lxcSetCpusetTune(virDomainDefPtr def, virConfPtr properties)
{ {
char *value = NULL; VIR_AUTOFREE(char *) value = NULL;
virBitmapPtr nodeset = NULL; virBitmapPtr nodeset = NULL;
if (virConfGetValueString(properties, "lxc.cgroup.cpuset.cpus", if (virConfGetValueString(properties, "lxc.cgroup.cpuset.cpus",
...@@ -830,6 +834,7 @@ lxcSetCpusetTune(virDomainDefPtr def, virConfPtr properties) ...@@ -830,6 +834,7 @@ lxcSetCpusetTune(virDomainDefPtr def, virConfPtr properties)
if (virBitmapParse(value, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) if (virBitmapParse(value, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0)
return -1; return -1;
def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC; def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC;
VIR_FREE(value);
} }
if (virConfGetValueString(properties, "lxc.cgroup.cpuset.mems", if (virConfGetValueString(properties, "lxc.cgroup.cpuset.mems",
...@@ -943,7 +948,7 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfValuePtr value, void *data) ...@@ -943,7 +948,7 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfValuePtr value, void *data)
static int static int
lxcSetBlkioTune(virDomainDefPtr def, virConfPtr properties) lxcSetBlkioTune(virDomainDefPtr def, virConfPtr properties)
{ {
char *value = NULL; VIR_AUTOFREE(char *) value = NULL;
if (virConfGetValueString(properties, "lxc.cgroup.blkio.weight", if (virConfGetValueString(properties, "lxc.cgroup.blkio.weight",
&value) > 0) { &value) > 0) {
...@@ -963,7 +968,7 @@ lxcSetBlkioTune(virDomainDefPtr def, virConfPtr properties) ...@@ -963,7 +968,7 @@ lxcSetBlkioTune(virDomainDefPtr def, virConfPtr properties)
static void static void
lxcSetCapDrop(virDomainDefPtr def, virConfPtr properties) lxcSetCapDrop(virDomainDefPtr def, virConfPtr properties)
{ {
char *value = NULL; VIR_AUTOFREE(char *) value = NULL;
char **toDrop = NULL; char **toDrop = NULL;
const char *capString; const char *capString;
size_t i; size_t i;
...@@ -990,7 +995,7 @@ lxcParseConfigString(const char *config, ...@@ -990,7 +995,7 @@ lxcParseConfigString(const char *config,
{ {
virDomainDefPtr vmdef = NULL; virDomainDefPtr vmdef = NULL;
virConfPtr properties = NULL; virConfPtr properties = NULL;
char *value = NULL; VIR_AUTOFREE(char *) value = NULL;
if (!(properties = virConfReadString(config, VIR_CONF_FLAG_LXC_FORMAT))) if (!(properties = virConfReadString(config, VIR_CONF_FLAG_LXC_FORMAT)))
return NULL; return NULL;
...@@ -1030,6 +1035,7 @@ lxcParseConfigString(const char *config, ...@@ -1030,6 +1035,7 @@ lxcParseConfigString(const char *config,
else if (arch == VIR_ARCH_NONE && STREQ(value, "amd64")) else if (arch == VIR_ARCH_NONE && STREQ(value, "amd64"))
arch = VIR_ARCH_X86_64; arch = VIR_ARCH_X86_64;
vmdef->os.arch = arch; vmdef->os.arch = arch;
VIR_FREE(value);
} }
if (VIR_STRDUP(vmdef->os.init, "/sbin/init") < 0) if (VIR_STRDUP(vmdef->os.init, "/sbin/init") < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册