From: Eric Blake Date: Thu, 18 Oct 2018 20:05:22 +0000 (-0500) Subject: qemu: Avoid memleak on failure to format blockjobs X-Git-Tag: v4.9.0-rc1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ffac10c971d4db55744a63a80b4b9db7f8872e00;p=thirdparty%2Flibvirt.git qemu: Avoid memleak on failure to format blockjobs 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 ACKed-by: Michal Privoznik --- diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f00f1b3fdb..ba3fff607a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -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; }