[libvirt-java] [PATCH 33/65] Fix memleak in DomainSnapshot.getXMLDesc

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

 



Signed-off-by: Claudio Bley <cbley@xxxxxxxxxx>
---
 src/main/java/org/libvirt/DomainSnapshot.java |   10 +++++++++-
 src/main/java/org/libvirt/jna/Libvirt.java    |    2 +-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/libvirt/DomainSnapshot.java b/src/main/java/org/libvirt/DomainSnapshot.java
index 4736a71..3013117 100644
--- a/src/main/java/org/libvirt/DomainSnapshot.java
+++ b/src/main/java/org/libvirt/DomainSnapshot.java
@@ -4,6 +4,8 @@ import org.libvirt.jna.DomainSnapshotPointer;
 import static org.libvirt.Library.libvirt;
 import static org.libvirt.ErrorHandler.processError;
 
+import com.sun.jna.Pointer;
+
 public class DomainSnapshot {
 
     /**
@@ -71,6 +73,12 @@ public class DomainSnapshot {
      * @return the XML document
      */
     public String getXMLDesc() throws LibvirtException {
-        return processError(libvirt.virDomainSnapshotGetXMLDesc(VDSP, 0));
+        Pointer p = processError(libvirt.virDomainSnapshotGetXMLDesc(VDSP, 0));
+
+        try {
+            return Library.getString(p);
+        } finally {
+            Library.free(p);
+        }
     }
 }
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java
index 2eb1cdc..33b5f8c 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -380,7 +380,7 @@ public interface Libvirt extends Library {
     DomainSnapshotPointer virDomainSnapshotCreateXML(DomainPointer virDomainPtr, String xmlDesc, int flags);
     DomainSnapshotPointer virDomainSnapshotCurrent(DomainPointer virDomainPtr, int flags);
     int virDomainSnapshotDelete(DomainSnapshotPointer virDomainSnapshotPtr, int flags);
-    String virDomainSnapshotGetXMLDesc(DomainSnapshotPointer virDomainSnapshotPtr, int flags);
+    Pointer virDomainSnapshotGetXMLDesc(DomainSnapshotPointer virDomainSnapshotPtr, int flags);
     int virDomainSnapshotFree(DomainSnapshotPointer virDomainSnapshotPtr);
     int virDomainSnapshotListNames(DomainPointer virDomainPtr, Pointer[] names, int nameslen, int flags);
     DomainSnapshotPointer virDomainSnapshotLookupByName(DomainPointer virDomainPtr, String name, int flags);
-- 
1.7.9.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]