We need to free the char* entries of the result array returned
ourselves.
Signed-off-by: Claudio Bley <cbley(a)av-test.de>
---
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 5666c66..2eb1cdc 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -305,7 +305,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.7.9.5