397dc2
From 5fe7795d5fa5061f0ba615472f9351f9d29abf48 Mon Sep 17 00:00:00 2001
397dc2
Message-Id: <5fe7795d5fa5061f0ba615472f9351f9d29abf48@dist-git>
397dc2
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
397dc2
Date: Fri, 2 Oct 2020 13:44:44 +0200
397dc2
Subject: [PATCH] check for NULL before calling g_regex_unref
397dc2
MIME-Version: 1.0
397dc2
Content-Type: text/plain; charset=UTF-8
397dc2
Content-Transfer-Encoding: 8bit
397dc2
397dc2
g_regex_unref reports an error if called with a NULL argument.
397dc2
397dc2
We have two cases in the code where we (possibly) call it on a NULL
397dc2
argument. The interesting one is in virDomainQemuMonitorEventCleanup.
397dc2
397dc2
Based on VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX, we unref
397dc2
data->regex, which has two problems:
397dc2
397dc2
* On the client side, flags is -1 so the comparison is true even if no
397dc2
  regex was used, reproducible by:
397dc2
  $ virsh qemu-monitor-event --timeout 1
397dc2
  which results in an ugly error:
397dc2
(process:1289846): GLib-CRITICAL **: 14:58:42.631: g_regex_unref: assertion 'regex != NULL' failed
397dc2
* On the server side, we only create the regex if both the flag and the
397dc2
  string are present, so it's possible to trigger this message by:
397dc2
  $ virsh qemu-monitor-event --regex --timeout 1
397dc2
397dc2
Use a non-NULL comparison instead of the flag to decide whether we need
397dc2
to unref the regex. And add a non-NULL check to the unref in the
397dc2
VirtualBox test too.
397dc2
397dc2
Signed-off-by: Ján Tomko <jtomko@redhat.com>
397dc2
Fixes: 71efb59a4de7c51b1bc889a316f1796ebf55738f
397dc2
https://bugzilla.redhat.com/show_bug.cgi?id=1876907
397dc2
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
397dc2
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
397dc2
(cherry picked from commit 92b252456ee6d6ffc6e39e62ce1ce6c50113e00e)
397dc2
397dc2
https://bugzilla.redhat.com/show_bug.cgi?id=1861176
397dc2
397dc2
Signed-off-by: Ján Tomko <jtomko@redhat.com>
397dc2
Message-Id: <7d3c84f6556d0d46ada037d5e56c831babba609f.1601639064.git.jtomko@redhat.com>
397dc2
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
397dc2
---
397dc2
 src/conf/domain_event.c     | 2 +-
397dc2
 tests/vboxsnapshotxmltest.c | 3 ++-
397dc2
 2 files changed, 3 insertions(+), 2 deletions(-)
397dc2
397dc2
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
397dc2
index 33fbf10406..d3acde0236 100644
397dc2
--- a/src/conf/domain_event.c
397dc2
+++ b/src/conf/domain_event.c
397dc2
@@ -2194,7 +2194,7 @@ virDomainQemuMonitorEventCleanup(void *opaque)
397dc2
     virDomainQemuMonitorEventData *data = opaque;
397dc2
 
397dc2
     VIR_FREE(data->event);
397dc2
-    if (data->flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX)
397dc2
+    if (data->regex)
397dc2
         g_regex_unref(data->regex);
397dc2
     if (data->freecb)
397dc2
         (data->freecb)(data->opaque);
397dc2
diff --git a/tests/vboxsnapshotxmltest.c b/tests/vboxsnapshotxmltest.c
397dc2
index d1a7522931..8577157020 100644
397dc2
--- a/tests/vboxsnapshotxmltest.c
397dc2
+++ b/tests/vboxsnapshotxmltest.c
397dc2
@@ -134,7 +134,8 @@ mymain(void)
397dc2
     DO_TEST("2disks-3snap-brother");
397dc2
 
397dc2
  cleanup:
397dc2
-    g_regex_unref(testSnapshotXMLVariableLineRegex);
397dc2
+    if (testSnapshotXMLVariableLineRegex)
397dc2
+        g_regex_unref(testSnapshotXMLVariableLineRegex);
397dc2
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
397dc2
 }
397dc2
 
397dc2
-- 
397dc2
2.28.0
397dc2