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

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



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


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