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

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



Signed-off-by: Claudio Bley <cbley av-test de>
---
 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 97907d0..67b6053 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -327,7 +327,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.7.9.5


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