[PATCH] Plug test-related leaks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Once I had a static "virsh" binary, I ran this:

    cd src && valgrind --leak-check=full ./virsh --connect \
      test://$PWD/../docs/testnode.xml list

which exposed some leaks.
I fixed them like this:

	Plug test-related leaks.
	* src/test.c (testLoadNetwork): Free forwardDev.
	(testLoadDomain): Free ctxt.
	(testLoadNetwork): Likewise.
	(testOpenFromFile): Likewise.

Signed-off-by: Jim Meyering <meyering@xxxxxxxxxx>
---
 src/test.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/test.c b/src/test.c
index d228b31..c46a045 100644
--- a/src/test.c
+++ b/src/test.c
@@ -351,9 +351,11 @@ static int testLoadDomain(virConnectPtr conn,
     privconn->domains[handle].onPoweroff = onPoweroff;
     privconn->domains[handle].onCrash = onCrash;

+    xmlXPathFreeContext(ctxt);
     return (handle);

  error:
+    xmlXPathFreeContext(ctxt);
     if (name)
         free(name);
     return (-1);
@@ -508,6 +510,7 @@ static int testLoadNetwork(virConnectPtr conn,
     if (forwardDev) {
         strncpy(privconn->networks[handle].forwardDev, forwardDev, sizeof(privconn->networks[handle].forwardDev)-1);
         privconn->networks[handle].forwardDev[sizeof(privconn->networks[handle].forwardDev)-1] = '\0';
+        free(forwardDev);
     }

     strncpy(privconn->networks[handle].ipAddress, ipaddress, sizeof(privconn->networks[handle].ipAddress)-1);
@@ -522,9 +525,12 @@ static int testLoadNetwork(virConnectPtr conn,
     strncpy(privconn->networks[handle].dhcpEnd, dhcpend, sizeof(privconn->networks[handle].dhcpEnd)-1);
     privconn->networks[handle].dhcpEnd[sizeof(privconn->networks[handle].dhcpEnd)-1] = '\0';
     free(dhcpend);
+    xmlXPathFreeContext(ctxt);
     return (handle);

  error:
+    xmlXPathFreeContext(ctxt);
+    free (forwardDev);
     if (ipaddress)
         free(ipaddress);
     if (ipnetmask)
@@ -833,11 +839,13 @@ static int testOpenFromFile(virConnectPtr conn,
         }
     }

+    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);

     return (0);

  error:
+    xmlXPathFreeContext(ctxt);
     if (domains != NULL)
         free(domains);
     if (networks != NULL)
--
1.5.4.rc5.1.g0fa73

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]