[libvirt] [PATCH] conf: plug memory leak on error

Eric Blake eblake at redhat.com
Thu Oct 13 22:14:10 UTC 2011


Detected by Coverity.  Leak present since commit 874e65a; and
while commit d50bb45 tried to fix the issue, it missed a path.

* src/conf/domain_conf.c (virDomainDefParseBootXML): Always clean
up useserial.
---

Pushing under the trivial rule.

 src/conf/domain_conf.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8cd493b..844af27 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6316,35 +6316,35 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
     useserial = virXPathString("string(./os/bios[1]/@useserial)", ctxt);
     if (useserial) {
         if (STREQ(useserial, "yes")) {
             if (virXPathULong("count(./devices/serial)",
                               ctxt, &serialPorts) < 0) {
                 virDomainReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                      _("need at least one serial port "
                                        "for useserial"));
                 goto cleanup;
             }
             def->os.bios.useserial = VIR_DOMAIN_BIOS_USESERIAL_YES;
         } else {
             def->os.bios.useserial = VIR_DOMAIN_BIOS_USESERIAL_NO;
         }
-        VIR_FREE(useserial);
     }

     *bootCount = deviceBoot;
     ret = 0;

 cleanup:
+    VIR_FREE(useserial);
     VIR_FREE(nodes);
     return ret;
 }

 /* Parse the XML definition for a vcpupin */
 static virDomainVcpuPinDefPtr
 virDomainVcpuPinDefParseXML(const xmlNodePtr node,
                             xmlXPathContextPtr ctxt,
                             int maxvcpus)
 {
     virDomainVcpuPinDefPtr def;
     xmlNodePtr oldnode = ctxt->node;
     unsigned int vcpuid;
     char *tmp = NULL;
-- 
1.7.4.4




More information about the libvir-list mailing list