This doesn't look at all right either. If nmachines is 0, then
machines
should already be NULL.
If you look at the code of virQEMUCapsGetMachineTypesCaps, you see:
int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
size_t *nmachines,
virCapsGuestMachinePtr **machines)
{
size_t i;
*nmachines = 0;
*machines = NULL;
if (VIR_ALLOC_N(*machines, qemuCaps->nmachineTypes) < 0)
goto error;
*nmachines = qemuCaps->nmachineTypes;
Even if we pass nmachines=0 to VIR_ALLOC_N , it emulates GNU behavior
of malloc(0) allocating a pointer, which is never freed, and hence
needs a VIR_FREE.
--
Nehal J Wani