[libvirt-java] [PATCH 06/10] Fix memleak in Domain.snapshotListNames

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

 



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

diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java
index 4463a9b..fc5486b 100644
--- a/src/main/java/org/libvirt/Domain.java
+++ b/src/main/java/org/libvirt/Domain.java
@@ -1183,15 +1183,15 @@ public class Domain {
      * @throws LibvirtException
      */
     public String[] snapshotListNames(int flags) throws LibvirtException {
-        String[] returnValue = null;
         int num = snapshotNum();
-        if (num >= 0) {
-            returnValue = new String[num];
-            if (num > 0) {
-                processError(libvirt.virDomainSnapshotListNames(VDP, returnValue, num, flags));
-            }
+        if (num > 0) {
+            Pointer[] ptrs = new Pointer[num];
+            int got = processError(libvirt.virDomainSnapshotListNames(VDP, ptrs, num, flags));
+
+            return Library.toStringArray(ptrs, got);
+        } else {
+            return Library.NO_STRINGS;
         }
-        return returnValue;
     }
 
     /**
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java
index a2bf42e..70e57d8 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -381,7 +381,7 @@ public interface Libvirt extends Library {
     int virDomainSnapshotDelete(DomainSnapshotPointer virDomainSnapshotPtr, int flags);
     String virDomainSnapshotGetXMLDesc(DomainSnapshotPointer virDomainSnapshotPtr, int flags);
     int virDomainSnapshotFree(DomainSnapshotPointer virDomainSnapshotPtr);
-    int virDomainSnapshotListNames(DomainPointer virDomainPtr, String[] names, int nameslen, int flags);
+    int virDomainSnapshotListNames(DomainPointer virDomainPtr, Pointer[] names, int nameslen, int flags);
     DomainSnapshotPointer virDomainSnapshotLookupByName(DomainPointer virDomainPtr, String name, int flags);
     int virDomainSnapshotNum(DomainPointer virDomainPtr, int flags);
 
-- 
1.8.5.2.msysgit.0

--
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]