mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 13:05:27 +00:00
Fix memory leaks in config file handling
This commit is contained in:
parent
a15c593c2e
commit
aea00ddb8c
@ -1,3 +1,9 @@
|
||||
Fri Jan 19 15:07:13 EST 2007 Daniel Berrange <berrange@redhat.com>
|
||||
|
||||
* src/conf.c: Free stored config parameters, when free'ing
|
||||
the virConfPtr object. For values, only free the object
|
||||
corresponding to the values' type
|
||||
|
||||
Thu Jan 18 16:12:13 EST 2007 Daniel Berrange <berrange@redhat.com>
|
||||
|
||||
* docs/testnode.xml, docs/testdomfc4.xml: Tweak memory settings to
|
||||
|
27
src/conf.c
27
src/conf.c
@ -137,9 +137,11 @@ virConfFreeValue(virConfValuePtr val)
|
||||
{
|
||||
if (val == NULL)
|
||||
return;
|
||||
if (val->str != NULL)
|
||||
if (val->type == VIR_CONF_STRING &&
|
||||
val->str != NULL)
|
||||
free(val->str);
|
||||
if (val->list != NULL)
|
||||
if (val->type == VIR_CONF_LIST &&
|
||||
val->list != NULL)
|
||||
virConfFreeList(val->list);
|
||||
free(val);
|
||||
}
|
||||
@ -204,6 +206,7 @@ virConfAddEntry(virConfPtr conf, char *name, virConfValuePtr value, char *comm)
|
||||
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
memset(ret, 0, sizeof(virConfEntry));
|
||||
ret->name = name;
|
||||
ret->value = value;
|
||||
@ -494,7 +497,6 @@ virConfParseValue(virConfParserCtxtPtr ctxt)
|
||||
ret->l = l;
|
||||
ret->str = str;
|
||||
ret->list = lst;
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
@ -760,10 +762,23 @@ virConfReadMem(const char *memory, int len)
|
||||
int
|
||||
virConfFree(virConfPtr conf)
|
||||
{
|
||||
virConfEntryPtr tmp;
|
||||
if (conf == NULL) {
|
||||
virConfError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__, 0);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
tmp = conf->entries;
|
||||
while (tmp) {
|
||||
virConfEntryPtr next;
|
||||
free(tmp->name);
|
||||
virConfFreeValue(tmp->value);
|
||||
if (tmp->comment)
|
||||
free(tmp->comment);
|
||||
next = tmp->next;
|
||||
free(tmp);
|
||||
tmp = next;
|
||||
}
|
||||
free(conf);
|
||||
return(0);
|
||||
}
|
||||
@ -818,12 +833,12 @@ int virConfSetValue (virConfPtr conf,
|
||||
prev = cur;
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
if (!cur) {
|
||||
if (!(cur = malloc(sizeof(virConfEntry)))) {
|
||||
virConfFreeValue(value);
|
||||
return (-1);
|
||||
}
|
||||
cur->next = NULL;
|
||||
cur->comment = NULL;
|
||||
if (!(cur->name = strdup(setting))) {
|
||||
virConfFreeValue(value);
|
||||
@ -832,8 +847,10 @@ int virConfSetValue (virConfPtr conf,
|
||||
}
|
||||
cur->value = value;
|
||||
if (prev) {
|
||||
cur->next = prev->next;
|
||||
prev->next = cur;
|
||||
} else {
|
||||
cur->next = conf->entries;
|
||||
conf->entries = cur;
|
||||
}
|
||||
} else {
|
||||
@ -935,7 +952,7 @@ virConfWriteMem(char *memory, int *len, virConfPtr conf)
|
||||
}
|
||||
memcpy(memory, buf->content, buf->use);
|
||||
ret = buf->use;
|
||||
|
||||
*len = buf->use;
|
||||
error:
|
||||
virBufferFree(buf);
|
||||
return(ret);
|
||||
|
Loading…
x
Reference in New Issue
Block a user