1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

virsh: fix event registration for single event

Allocate a larger 'data' array than strictly needed
for simplicity and use 'ndata' as the index when
filling it to put the single event at the first unused
place, instead of at its index in the virshDomainEventCallbacks
array.

https://bugzilla.redhat.com/show_bug.cgi?id=2073887

Fixes: c6bb274693
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2022-04-11 09:30:12 +02:00
parent c11fb2132f
commit df757e88fd

View File

@ -915,23 +915,20 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd)
return false;
}
if (eventName)
data = g_new0(virshDomEventData, 1);
else
data = g_new0(virshDomEventData, G_N_ELEMENTS(virshDomainEventCallbacks));
data = g_new0(virshDomEventData, G_N_ELEMENTS(virshDomainEventCallbacks));
for (i = 0; i < G_N_ELEMENTS(virshDomainEventCallbacks); i++) {
if (eventName &&
STRNEQ(eventName, virshDomainEventCallbacks[i].name))
continue;
data[i].event = i;
data[i].ctl = ctl;
data[i].loop = loop;
data[i].count = &count;
data[i].timestamp = timestamp;
data[i].cb = &virshDomainEventCallbacks[i];
data[i].id = -1;
data[ndata].event = i;
data[ndata].ctl = ctl;
data[ndata].loop = loop;
data[ndata].count = &count;
data[ndata].timestamp = timestamp;
data[ndata].cb = &virshDomainEventCallbacks[i];
data[ndata].id = -1;
ndata++;
}