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

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



---
 src/main/java/org/libvirt/StorageVol.java  | 10 +++++++++-
 src/main/java/org/libvirt/jna/Libvirt.java |  2 +-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/libvirt/StorageVol.java b/src/main/java/org/libvirt/StorageVol.java
index 1573070..7035c93 100644
--- a/src/main/java/org/libvirt/StorageVol.java
+++ b/src/main/java/org/libvirt/StorageVol.java
@@ -6,6 +6,8 @@ import org.libvirt.jna.virStorageVolInfo;
 import static org.libvirt.Library.libvirt;
 import static org.libvirt.ErrorHandler.processError;
 
+import com.sun.jna.Pointer;
+
 /**
  * An acutal storage bucket.
  */
@@ -161,7 +163,13 @@ public class StorageVol {
      * @throws LibvirtException
      */
     public String getPath() throws LibvirtException {
-        return processError(libvirt.virStorageVolGetPath(VSVP));
+        Pointer p = processError(libvirt.virStorageVolGetPath(VSVP));
+
+        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 4017269..8033791 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -325,7 +325,7 @@ public interface Libvirt extends Library {
     int virStorageVolGetInfo(StorageVolPointer storageVolPtr, virStorageVolInfo info);
     String virStorageVolGetKey(StorageVolPointer storageVolPtr);
     String virStorageVolGetName(StorageVolPointer storageVolPtr);
-    String virStorageVolGetPath(StorageVolPointer storageVolPtr);
+    Pointer virStorageVolGetPath(StorageVolPointer storageVolPtr);
     String virStorageVolGetXMLDesc(StorageVolPointer storageVolPtr, int flags);
     StorageVolPointer virStorageVolLookupByKey(ConnectionPointer virConnectPtr, String name);
     StorageVolPointer virStorageVolLookupByName(StoragePoolPointer storagePoolPtr, String name);
-- 
1.8.5.2.msysgit.0


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