Skip to content
Failed

Changes

Summary

  1. Fix Domain.getJobStats (details)
  2. Fix incorrect argument type in virDomainMigrate3 (details)
Commit 48dfbc13274c3b819c0b35ac6026670308f996c0 by mitsuru.kariya
Fix Domain.getJobStats

Fix the following issues in Domain.getJobStats:
- Fix an exception that occurred when the virTypedParameter[] had zero
  elements.
  virDomainGetJobStats returns successfully with *params == NULL and
  *nparams == 0 when *type == VIR_DOMAIN_JOB_NONE.
  However, calling Structure.toArray(n) with n == 0 causes an
  ArrayIndexOutOfBoundsException.
  This is avoided by directly returning an empty array when *nparams == 0.
- Fix the issue where the first element of virTypedParameter[] was not
  being read.
  The Structure constructor does not automatically read fields.
  This is fixed by explicitly calling the virTypedParameter.read() method
  for the first element.
  Note: Structure.toArray(n) automatically reads fields (i.e., calls the
  virTypedParameter.read() method) for all elements except the first.
- Fix the issue where the value was not being read when virTypedParameter
  was a String.
  Union does not perform pointer-to-value reads (such as char* -> String)
  unless it is the active element.
  This is fixed by explicitly reading the String when
  virTypedParameter.type == VIR_TYPED_STRING.
- Fix a potential crash in virTypedParamsFree when handling String
  parameters.
  When passing a Structure received from a native function as an argument
  to another native function:
    - String fields directly embedded in the Structure are not updated in
      native memory if their values haven't changed.
    - However, Unions embedded in the Structure always update native memory
      for the active element, even if the value hasn't changed.
  Therefore, if the active element of the Union is a String, JNA allocates
  new memory for the string and overwrites the received char* pointer.
  This not only causes the original char* pointer to be leaked, but also
  leads to double-free issues: once by virTypedParamsFree and again by GC
  on the JNA-allocated memory.
  This is avoided by changing the argument type of virTypedParamsFree from
  virTypedParameter[] to Pointer.

Additionally, extract the conversion from a pointer to a virTypedParameter
array to a TypedParameter array into a static method of TypedParameter, as
there are other functions that also receive virTypedParameter arrays.

Signed-off-by: Mitsuru Kariya <mitsuru.kariya@nttdata.com>
The file was modifiedsrc/main/java/org/libvirt/TypedParameter.java (diff)
The file was modifiedsrc/main/java/org/libvirt/Domain.java (diff)
The file was modifiedsrc/main/java/org/libvirt/jna/virTypedParameter.java (diff)
The file was modifiedsrc/main/java/org/libvirt/jna/Libvirt.java (diff)
Commit c945e7c08c9b0d791d3804480cf74d1b08a4046f by dan-gitlab
Fix incorrect argument type in virDomainMigrate3

The 5th argument `flags` of `virDomainMigrate3` is `unsigned int`, not
`unsigned long`.  Therefore, the Java binding should use `int` instead of
`NativeLong`.

To maintain backward compatibility, the version taking `NativeLong` as an
argument has been deprecated, and a new version taking `int` has been added.

Although not fully verified, it is likely that no practical issue occurs on
supported platforms because:

- On 32-bit platforms, `long` and `int` are the same size.
- On 64-bit platforms, the 5th argument is passed via a register.

Signed-off-by: Mitsuru Kariya <mitsuru.kariya@nttdata.com>
The file was modifiedsrc/main/java/org/libvirt/Domain.java (diff)
The file was modifiedsrc/main/java/org/libvirt/jna/Libvirt.java (diff)