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

[libvirt] [libvirt-java] [PATCH 07/10] Fix memleak in StoragePool.listVolumes



We need to free the char* entries of the result array returned
ourselves.
---
 src/main/java/org/libvirt/StoragePool.java | 13 ++++++++++---
 src/main/java/org/libvirt/jna/Libvirt.java |  2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/libvirt/StoragePool.java b/src/main/java/org/libvirt/StoragePool.java
index bb608e3..14ecab8 100644
--- a/src/main/java/org/libvirt/StoragePool.java
+++ b/src/main/java/org/libvirt/StoragePool.java
@@ -8,6 +8,7 @@ import static org.libvirt.Library.libvirt;
 import static org.libvirt.ErrorHandler.processError;
 
 import com.sun.jna.Native;
+import com.sun.jna.Pointer;
 import com.sun.jna.ptr.IntByReference;
 
 /**
@@ -245,9 +246,15 @@ public class StoragePool {
      */
     public String[] listVolumes() throws LibvirtException {
         int num = numOfVolumes();
-        String[] returnValue = new String[num];
-        processError(libvirt.virStoragePoolListVolumes(VSPP, returnValue, num));
-        return returnValue;
+        if (num > 0) {
+            Pointer[] ptrs = new Pointer[num];
+
+            int got = processError(libvirt.virStoragePoolListVolumes(VSPP, ptrs, num));
+
+            return Library.toStringArray(ptrs, got);
+        } else {
+            return Library.NO_STRINGS;
+        }
     }
 
     /**
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java
index 70e57d8..e0096e3 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -304,7 +304,7 @@ public interface Libvirt extends Library {
     int virStoragePoolGetUUID(StoragePoolPointer storagePoolPtr, byte[] uuidString);
     int virStoragePoolGetUUIDString(StoragePoolPointer storagePoolPtr, byte[] uuidString);
     String virStoragePoolGetXMLDesc(StoragePoolPointer storagePoolPtr, int flags);
-    int virStoragePoolListVolumes(StoragePoolPointer storagePoolPtr, String[] names, int maxnames);
+    int virStoragePoolListVolumes(StoragePoolPointer storagePoolPtr, Pointer[] names, int maxnames);
     int virStoragePoolIsActive(StoragePoolPointer storagePoolPtr);
     int virStoragePoolIsPersistent(StoragePoolPointer storagePoolPtr);
     StoragePoolPointer virStoragePoolLookupByName(ConnectionPointer virConnectPtr, String name);
-- 
1.8.5.2.msysgit.0


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