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

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

 



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

--
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]