The getSchedulerType method returns a String (the name of the scheduler), not a String array containing a single element. It's OK to just pass null for the second argument to virDomainGetSchedulerType. Ensure to free the returned string. Signed-off-by: Claudio Bley <cbley@xxxxxxxxxx> --- src/main/java/org/libvirt/Domain.java | 43 +++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index ab6f9f0..6db8745 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -528,18 +528,25 @@ public class Domain { */ public SchedParameter[] getSchedulerParameters() throws LibvirtException { IntByReference nParams = new IntByReference(); - SchedParameter[] returnValue = new SchedParameter[0]; - Pointer pScheduler = processError(libvirt.virDomainGetSchedulerType(VDP, nParams)); - String scheduler = Library.getString(pScheduler); - Library.free(pScheduler); - virSchedParameter[] nativeParams = new virSchedParameter[nParams.getValue()]; - returnValue = new SchedParameter[nParams.getValue()]; - processError(libvirt.virDomainGetSchedulerParameters(VDP, nativeParams, nParams)); - for (int x = 0; x < nParams.getValue(); x++) { - returnValue[x] = SchedParameter.create(nativeParams[x]); - } + Library.free(processError(libvirt.virDomainGetSchedulerType(VDP, nParams))); - return returnValue; + int n = nParams.getValue(); + + if (n > 0) { + virSchedParameter[] nativeParams = new virSchedParameter[n]; + + processError(libvirt.virDomainGetSchedulerParameters(VDP, nativeParams, nParams)); + n = nParams.getValue(); + + SchedParameter[] returnValue = new SchedParameter[n]; + + for (int x = 0; x < n; x++) { + returnValue[x] = SchedParameter.create(nativeParams[x]); + } + return returnValue; + } else { + return new SchedParameter[] {}; + } } // getSchedulerType @@ -552,13 +559,13 @@ public class Domain { * @return the type of the scheduler * @throws LibvirtException */ - public String[] getSchedulerType() throws LibvirtException { - IntByReference nParams = new IntByReference(); - Pointer pScheduler = processError(libvirt.virDomainGetSchedulerType(VDP, nParams)); - String[] array = new String[1]; - array[0] = Library.getString(pScheduler); - Library.free(pScheduler); - return array; + public String getSchedulerType() throws LibvirtException { + Pointer pScheduler = processError(libvirt.virDomainGetSchedulerType(VDP, null)); + try { + return Library.getString(pScheduler); + } finally { + Library.free(pScheduler); + } } /** -- 1.7.9.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list