[libvirt] [PATCH] network: plug memory leak

Eric Blake eblake at redhat.com
Mon Jan 10 22:38:17 UTC 2011


* src/conf/network_conf.c (virNetworkDefParseXML): Release ipNodes.
---

Another memleak found by valgrind; shown with additional context
to make review easier.

 src/conf/network_conf.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index abe91b5..28a3ee8 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1,22 +1,22 @@
 /*
  * network_conf.c: network XML handling
  *
- * Copyright (C) 2006-2010 Red Hat, Inc.
+ * Copyright (C) 2006-2011 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  *
  * Author: Daniel P. Berrange <berrange at redhat.com>
  */
@@ -631,67 +631,69 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
     nIps = virXPathNodeSet("./ip", ctxt, &ipNodes);
     if (nIps > 0) {
         int ii;

         /* allocate array to hold all the addrs */
         if (VIR_ALLOC_N(def->ips, nIps) < 0) {
             virReportOOMError();
             goto error;
         }
         /* parse each addr */
         for (ii = 0; ii < nIps; ii++) {
             int ret = virNetworkIPParseXML(def->name, &def->ips[ii],
                                            ipNodes[ii], ctxt);
             if (ret < 0)
                 goto error;
             def->nips++;
         }
     }
+    VIR_FREE(ipNodes);

     /* IPv4 forwarding setup */
     if (virXPathBoolean("count(./forward) > 0", ctxt)) {
         if (def->nips == 0) {
             virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
                                   "%s", _("Forwarding requested, but no IP address provided"));
             goto error;
         }
         tmp = virXPathString("string(./forward[1]/@mode)", ctxt);
         if (tmp) {
             if ((def->forwardType = virNetworkForwardTypeFromString(tmp)) < 0) {
                 virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
                                       _("unknown forwarding type '%s'"), tmp);
                 VIR_FREE(tmp);
                 goto error;
             }
             VIR_FREE(tmp);
         } else {
             def->forwardType = VIR_NETWORK_FORWARD_NAT;
         }


         def->forwardDev = virXPathString("string(./forward[1]/@dev)", ctxt);
     } else {
         def->forwardType = VIR_NETWORK_FORWARD_NONE;
     }

     return def;

  error:
     virNetworkDefFree(def);
+    VIR_FREE(ipNodes);
     return NULL;
 }

 static virNetworkDefPtr
 virNetworkDefParse(const char *xmlStr,
                    const char *filename)
 {
     xmlDocPtr xml;
     virNetworkDefPtr def = NULL;

     if ((xml = virXMLParse(filename, xmlStr, "network.xml"))) {
         def = virNetworkDefParseNode(xml, xmlDocGetRootElement(xml));
         xmlFreeDoc(xml);
     }

     return def;
 }

-- 
1.7.3.4




More information about the libvir-list mailing list