[libvirt-java] [PATCH 35/65] Fix memleak in StorageVol.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/StorageVol.java  |    8 +++++++-
 src/main/java/org/libvirt/jna/Libvirt.java |    2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/libvirt/StorageVol.java b/src/main/java/org/libvirt/StorageVol.java
index 7035c93..47b79f6 100644
--- a/src/main/java/org/libvirt/StorageVol.java
+++ b/src/main/java/org/libvirt/StorageVol.java
@@ -181,7 +181,13 @@ public class StorageVol {
      * @throws LibvirtException
      */
     public String getXMLDesc(int flags) throws LibvirtException {
-        return processError(libvirt.virStorageVolGetXMLDesc(VSVP, flags));
+        Pointer p = processError(libvirt.virStorageVolGetXMLDesc(VSVP, flags));
+
+        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 97907d0..67b6053 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -327,7 +327,7 @@ public interface Libvirt extends Library {
     String virStorageVolGetKey(StorageVolPointer storageVolPtr);
     String virStorageVolGetName(StorageVolPointer storageVolPtr);
     Pointer virStorageVolGetPath(StorageVolPointer storageVolPtr);
-    String virStorageVolGetXMLDesc(StorageVolPointer storageVolPtr, int flags);
+    Pointer virStorageVolGetXMLDesc(StorageVolPointer storageVolPtr, int flags);
     StorageVolPointer virStorageVolLookupByKey(ConnectionPointer virConnectPtr, String name);
     StorageVolPointer virStorageVolLookupByName(StoragePoolPointer storagePoolPtr, String name);
     StorageVolPointer virStorageVolLookupByPath(ConnectionPointer virConnectPtr, String path);
-- 
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]