[libvirt] [PATCH] Fix a memory leak in virsh.

Laine Stump laine at laine.org
Sun Aug 30 19:59:08 UTC 2009


I found this while looking for examples of using
virNodeDeviceGetXMLDesc(). AFAIK, *all* of the *GetXMLDesc() functions
return a newly allocated chunk of memory that is owned by the caller,
who must free it when they're done...

---
 src/virsh.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/virsh.c b/src/virsh.c
index 15e0cef..910d860 100644
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -5521,6 +5521,7 @@ cmdNodeDeviceDumpXML (vshControl *ctl, const vshCmd *cmd)
 {
     const char *name;
     virNodeDevicePtr device;
+    char *xml;
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
@@ -5531,7 +5532,14 @@ cmdNodeDeviceDumpXML (vshControl *ctl, const vshCmd *cmd)
         return FALSE;
     }
 
-    vshPrint(ctl, "%s\n", virNodeDeviceGetXMLDesc(device, 0));
+    xml = virNodeDeviceGetXMLDesc(device, 0);
+    if (!xml) {
+        virNodeDeviceFree(device);
+        return FALSE;
+    }
+
+    vshPrint(ctl, "%s\n", xml);
+    free(xml);
     virNodeDeviceFree(device);
     return TRUE;
 }
-- 
1.6.2.5




More information about the libvir-list mailing list