From 7487eaefca026da3b0ccc8e8872a8e7ba0101640 Mon Sep 17 00:00:00 2001
From: Feng Ni <fengni@huawei.com>
Date: Thu, 25 Jul 2019 15:37:14 +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>
---
 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 731be2e..a5eeec6 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1103,7 +1103,7 @@ qemuMonitorSend(qemuMonitorPtr mon,
 virErrorPtr
 qemuMonitorLastError(qemuMonitorPtr mon)
 {
-    if (mon->lastError.code == VIR_ERR_OK)
+    if (!mon || mon->lastError.code == VIR_ERR_OK)
         return NULL;
 
     return virErrorCopyNew(&mon->lastError);
-- 
2.19.1

