Peter Krempa (2):
conf: Fix memory leak in graphics XML parser
conf: Fix label name in virDomainGraphicsListensParseXML
src/conf/domain_conf.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
--
2.8.3
Show replies by date
When loading status XMLs with following graphics definition:
<graphics type='spice' port='5900' autoport='yes'
listen='127.0.0.1'>
<listen type='address' address='127.0.0.1'
fromConfig='1'/>
<image compression='off'/>
</graphics>
libvirtd would leak a few bytes:
10 bytes in 1 blocks are definitely lost in loss record 71 of 1,127
at 0x4C2C000: malloc (vg_replace_malloc.c:299)
by 0x6789298: xmlStrndup (in /usr/lib64/libxml2.so.2.9.4)
by 0x552AB0A: virXMLPropString (virxml.c:479)
by 0x5539536: virDomainGraphicsListensParseXML (domain_conf.c:11171)
by 0x553DD5E: virDomainGraphicsDefParseXMLSpice (domain_conf.c:11414)
by 0x553DD5E: virDomainGraphicsDefParseXML (domain_conf.c:11749)
by 0x5566061: virDomainDefParseXML (domain_conf.c:16939)
by 0x556953F: virDomainObjParseXML (domain_conf.c:17348)
by 0x556953F: virDomainObjParseNode (domain_conf.c:17513)
by 0x5569902: virDomainObjParseFile (domain_conf.c:17532)
by 0x5571E02: virDomainObjListLoadStatus (virdomainobjlist.c:514)
by 0x5571E02: virDomainObjListLoadAllConfigs (virdomainobjlist.c:596)
by 0x26E0BDC8: qemuStateInitialize (qemu_driver.c:911)
by 0x55B1FDB: virStateInitialize (libvirt.c:770)
by 0x122039: daemonRunStateInit (libvirtd.c:960)
---
There might be some other for me invisible bug in the logic of handling of the
glisten definition which might make this disappear too, but I'm not really into
this code.
src/conf/domain_conf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fb6f58d..0b642a1 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11190,13 +11190,13 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
newListen.type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET) {
virDomainGraphicsListenDefClear(glisten);
*glisten = newListen;
+ memset(&newListen, 0, sizeof(newListen));
}
}
ret = 0;
error:
- if (ret < 0)
- virDomainGraphicsListenDefClear(&newListen);
+ virDomainGraphicsListenDefClear(&newListen);
VIR_FREE(listenNodes);
VIR_FREE(socketPath);
ctxt->node = save;
--
2.8.3
Use 'cleanup' since it's also used on success.
---
src/conf/domain_conf.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0b642a1..f208682 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11136,20 +11136,20 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
/* parse the <listen> subelements for graphics types that support it */
nListens = virXPathNodeSet("./listen", ctxt, &listenNodes);
if (nListens < 0)
- goto error;
+ goto cleanup;
if (nListens > 0) {
size_t i;
if (VIR_ALLOC_N(def->listens, nListens) < 0)
- goto error;
+ goto cleanup;
for (i = 0; i < nListens; i++) {
if (virDomainGraphicsListenDefParseXML(&def->listens[i], def,
listenNodes[i],
i == 0 ? node : NULL,
flags) < 0)
- goto error;
+ goto cleanup;
def->nListens++;
}
@@ -11177,7 +11177,7 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
* <graphics/> element. */
if (def->nListens == 0) {
if (VIR_APPEND_ELEMENT(def->listens, def->nListens, newListen) < 0)
- goto error;
+ goto cleanup;
} else {
virDomainGraphicsListenDefPtr glisten = &def->listens[0];
@@ -11195,7 +11195,7 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
}
ret = 0;
- error:
+ cleanup:
virDomainGraphicsListenDefClear(&newListen);
VIR_FREE(listenNodes);
VIR_FREE(socketPath);
--
2.8.3