]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
check for NULL before calling g_regex_unref
authorJán Tomko <jtomko@redhat.com>
Tue, 8 Sep 2020 12:57:14 +0000 (14:57 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 8 Sep 2020 14:07:47 +0000 (16:07 +0200)
g_regex_unref reports an error if called with a NULL argument.

We have two cases in the code where we (possibly) call it on a NULL
argument. The interesting one is in virDomainQemuMonitorEventCleanup.

Based on VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX, we unref
data->regex, which has two problems:

* On the client side, flags is -1 so the comparison is true even if no
  regex was used, reproducible by:
  $ virsh qemu-monitor-event --timeout 1
  which results in an ugly error:
(process:1289846): GLib-CRITICAL **: 14:58:42.631: g_regex_unref: assertion 'regex != NULL' failed
* On the server side, we only create the regex if both the flag and the
  string are present, so it's possible to trigger this message by:
  $ virsh qemu-monitor-event --regex --timeout 1

Use a non-NULL comparison instead of the flag to decide whether we need
to unref the regex. And add a non-NULL check to the unref in the
VirtualBox test too.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: 71efb59a4de7c51b1bc889a316f1796ebf55738f
https://bugzilla.redhat.com/show_bug.cgi?id=1876907
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/conf/domain_event.c
tests/vboxsnapshotxmltest.c

index 33fbf1040627fc36260841c9013276306fdc2cbb..d3acde023670f2da7bb738f3980560fed4d43578 100644 (file)
@@ -2194,7 +2194,7 @@ virDomainQemuMonitorEventCleanup(void *opaque)
     virDomainQemuMonitorEventData *data = opaque;
 
     VIR_FREE(data->event);
-    if (data->flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX)
+    if (data->regex)
         g_regex_unref(data->regex);
     if (data->freecb)
         (data->freecb)(data->opaque);
index 7e3f85cc586cc689482ba1462709d91a1fb14d29..d2beb7858d2a06d5b42c5eba7753b9f1d5a1ea6d 100644 (file)
@@ -135,7 +135,8 @@ mymain(void)
     DO_TEST("2disks-3snap-brother");
 
  cleanup:
-    g_regex_unref(testSnapshotXMLVariableLineRegex);
+    if (testSnapshotXMLVariableLineRegex)
+        g_regex_unref(testSnapshotXMLVariableLineRegex);
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }