Commit
48dfbc13274c3b819c0b35ac6026670308f996c0
by mitsuru.kariyaFix 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>