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>
|
Thu Jan 18 16:12:13 EST 2007 Daniel Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* docs/testnode.xml, docs/testdomfc4.xml: Tweak memory settings to
|
* docs/testnode.xml, docs/testdomfc4.xml: Tweak memory settings to
|
||||||
|
41
src/conf.c
41
src/conf.c
@ -120,9 +120,9 @@ virConfFreeList(virConfValuePtr list)
|
|||||||
|
|
||||||
while (list != NULL) {
|
while (list != NULL) {
|
||||||
next = list->next;
|
next = list->next;
|
||||||
list->next = NULL;
|
list->next = NULL;
|
||||||
virConfFreeValue(list);
|
virConfFreeValue(list);
|
||||||
list = next;
|
list = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,9 +137,11 @@ virConfFreeValue(virConfValuePtr val)
|
|||||||
{
|
{
|
||||||
if (val == NULL)
|
if (val == NULL)
|
||||||
return;
|
return;
|
||||||
if (val->str != NULL)
|
if (val->type == VIR_CONF_STRING &&
|
||||||
|
val->str != NULL)
|
||||||
free(val->str);
|
free(val->str);
|
||||||
if (val->list != NULL)
|
if (val->type == VIR_CONF_LIST &&
|
||||||
|
val->list != NULL)
|
||||||
virConfFreeList(val->list);
|
virConfFreeList(val->list);
|
||||||
free(val);
|
free(val);
|
||||||
}
|
}
|
||||||
@ -204,6 +206,7 @@ virConfAddEntry(virConfPtr conf, char *name, virConfValuePtr value, char *comm)
|
|||||||
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
|
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(ret, 0, sizeof(virConfEntry));
|
memset(ret, 0, sizeof(virConfEntry));
|
||||||
ret->name = name;
|
ret->name = name;
|
||||||
ret->value = value;
|
ret->value = value;
|
||||||
@ -494,7 +497,6 @@ virConfParseValue(virConfParserCtxtPtr ctxt)
|
|||||||
ret->l = l;
|
ret->l = l;
|
||||||
ret->str = str;
|
ret->str = str;
|
||||||
ret->list = lst;
|
ret->list = lst;
|
||||||
|
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -760,9 +762,22 @@ virConfReadMem(const char *memory, int len)
|
|||||||
int
|
int
|
||||||
virConfFree(virConfPtr conf)
|
virConfFree(virConfPtr conf)
|
||||||
{
|
{
|
||||||
|
virConfEntryPtr tmp;
|
||||||
if (conf == NULL) {
|
if (conf == NULL) {
|
||||||
virConfError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__, 0);
|
virConfError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__, 0);
|
||||||
return(-1);
|
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);
|
free(conf);
|
||||||
return(0);
|
return(0);
|
||||||
@ -818,12 +833,12 @@ int virConfSetValue (virConfPtr conf,
|
|||||||
prev = cur;
|
prev = cur;
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cur) {
|
if (!cur) {
|
||||||
if (!(cur = malloc(sizeof(virConfEntry)))) {
|
if (!(cur = malloc(sizeof(virConfEntry)))) {
|
||||||
virConfFreeValue(value);
|
virConfFreeValue(value);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
cur->next = NULL;
|
|
||||||
cur->comment = NULL;
|
cur->comment = NULL;
|
||||||
if (!(cur->name = strdup(setting))) {
|
if (!(cur->name = strdup(setting))) {
|
||||||
virConfFreeValue(value);
|
virConfFreeValue(value);
|
||||||
@ -832,8 +847,10 @@ int virConfSetValue (virConfPtr conf,
|
|||||||
}
|
}
|
||||||
cur->value = value;
|
cur->value = value;
|
||||||
if (prev) {
|
if (prev) {
|
||||||
|
cur->next = prev->next;
|
||||||
prev->next = cur;
|
prev->next = cur;
|
||||||
} else {
|
} else {
|
||||||
|
cur->next = conf->entries;
|
||||||
conf->entries = cur;
|
conf->entries = cur;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -925,17 +942,17 @@ virConfWriteMem(char *memory, int *len, virConfPtr conf)
|
|||||||
cur = conf->entries;
|
cur = conf->entries;
|
||||||
while (cur != NULL) {
|
while (cur != NULL) {
|
||||||
virConfSaveEntry(buf, cur);
|
virConfSaveEntry(buf, cur);
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((int) buf->use >= *len) {
|
if ((int) buf->use >= *len) {
|
||||||
*len = buf->use;
|
*len = buf->use;
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
memcpy(memory, buf->content, buf->use);
|
memcpy(memory, buf->content, buf->use);
|
||||||
ret = buf->use;
|
ret = buf->use;
|
||||||
|
*len = buf->use;
|
||||||
error:
|
error:
|
||||||
virBufferFree(buf);
|
virBufferFree(buf);
|
||||||
return(ret);
|
return(ret);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user