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

[libvirt] [libvirt-java] [PATCH 10/10] Fix memleak in StorageVol.getXMLDesc



---
 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 8033791..eb29ec7 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -326,7 +326,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.8.5.2.msysgit.0


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