From 7461beaf732475406e39375ea8e1c6311140046f Mon Sep 17 00:00:00 2001
From: Feng Ni <fengni@huawei.com>
Date: Wed, 15 Apr 2020 11:14:35 +0800
Subject: [PATCH] qemu: add pointer check in qemuMonitorLastError

We found a exception when libvirt occurrs segmentation fault.
thread 1 is waiting object lock in qemuConnectMonitor,
qemu process exits and sends EOF event as well, so thread 2 invokes
qemuMonitorLastError but pointer mon is NULL.

Signed-off-by: Feng Ni <fengni@huawei.com>
Signed-off-by: Xu Yandong <xuyandong2@huawei.com>
---
 src/qemu/qemu_monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index ec586b9036..a69ead6109 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -893,7 +893,7 @@ qemuMonitorSend(qemuMonitor *mon,
 virErrorPtr
 qemuMonitorLastError(qemuMonitor *mon)
 {
-    if (mon->lastError.code == VIR_ERR_OK)
+    if (!mon || mon->lastError.code == VIR_ERR_OK)
         return NULL;
 
     return virErrorCopyNew(&mon->lastError);
-- 
2.27.0

