[libvirt PATCH] virsh: fix event registration for single event

Ján Tomko posted 1 patch 2 years ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/b3a414669a65a25387e2ae6ffd48fd2448cecbef.1649662402.git.jtomko@redhat.com
tools/virsh-domain-event.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
[libvirt PATCH] virsh: fix event registration for single event
Posted by Ján Tomko 2 years ago
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: c6bb2746933bbe65877a5f8a8d60e100b0bf8a59
Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
 tools/virsh-domain-event.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/tools/virsh-domain-event.c b/tools/virsh-domain-event.c
index 1a2f1cb6e0..6dbb64a655 100644
--- a/tools/virsh-domain-event.c
+++ b/tools/virsh-domain-event.c
@@ -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++;
     }
 
-- 
2.35.1

Re: [libvirt PATCH] virsh: fix event registration for single event
Posted by Michal Prívozník 2 years ago
On 4/11/22 09:33, Ján Tomko wrote:
> 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: c6bb2746933bbe65877a5f8a8d60e100b0bf8a59
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> ---
>  tools/virsh-domain-event.c | 19 ++++++++-----------
>  1 file changed, 8 insertions(+), 11 deletions(-)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal