mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 18:05:20 +00:00
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: John Ferlan <jferlan@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
f6399b9d89
commit
996f101431
@ -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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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,23 +792,25 @@ 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",
|
||||||
&value) > 0) {
|
&value) > 0) {
|
||||||
if (virStrToLong_ull(value, NULL, 10, &def->cputune.period) < 0)
|
if (virStrToLong_ull(value, NULL, 10, &def->cputune.period) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -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,10 +834,11 @@ 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",
|
||||||
&value) > 0) {
|
&value) > 0) {
|
||||||
if (virBitmapParse(value, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
|
if (virBitmapParse(value, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (virDomainNumatuneSet(def->numa,
|
if (virDomainNumatuneSet(def->numa,
|
||||||
@ -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)
|
|||||||
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,
|
|||||||
{
|
{
|
||||||
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,
|
|||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user