]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Avoid memleak on failure to format blockjobs
authorEric Blake <eblake@redhat.com>
Thu, 18 Oct 2018 20:05:22 +0000 (15:05 -0500)
committerEric Blake <eblake@redhat.com>
Fri, 19 Oct 2018 15:33:19 +0000 (10:33 -0500)
virXMLFormatElement() frees attrBuf on success, but not necessarily
on failure. Most other callers of this function take the time to
reset attrBuf afterwords, but qemuDomainObjPrivateXMLFormatBlockjobs()
was relying on it succeeding, and could thus result in a memory leak.

Signed-off-by: Eric Blake <eblake@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_domain.c

index f00f1b3fdb8a4bf7be2521e8ea219d78560cf6c1..ba3fff607a93533b9b47956cc2cfa70237e7c041 100644 (file)
@@ -2232,11 +2232,14 @@ qemuDomainObjPrivateXMLFormatBlockjobs(virBufferPtr buf,
 {
     virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
     bool bj = qemuDomainHasBlockjob(vm, false);
+    int ret;
 
     virBufferAsprintf(&attrBuf, " active='%s'",
                       virTristateBoolTypeToString(virTristateBoolFromBool(bj)));
 
-    return virXMLFormatElement(buf, "blockjobs", &attrBuf, NULL);
+    ret = virXMLFormatElement(buf, "blockjobs", &attrBuf, NULL);
+    virBufferFreeAndReset(&attrBuf);
+    return ret;
 }