From d2be5a59d36a743505185c0f5bb636088a6e37da Mon Sep 17 00:00:00 2001
From: Wu Jing <wujing42@huawei.com>
Date: Thu, 15 Aug 2019 19:33:16 +0800
Subject: [PATCH] libvirtd: fix driver cleanup order to avoid coredump

In cleanup process, there may be some threads still working and accessing objs
of drivers. We should put virStateCleanup at the end.

Signed-off-by: Wu Jing <wujing42@huawei.com>
---
 src/remote/remote_daemon.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c
index fdc9e43..ece4baa 100644
--- a/src/remote/remote_daemon.c
+++ b/src/remote/remote_daemon.c
@@ -1379,13 +1379,6 @@ int main(int argc, char **argv) {

     virNetlinkEventServiceStopAll();

-    if (driversInitialized) {
-        /* NB: Possible issue with timing window between driversInitialized
-         * setting if virNetlinkEventServerStart fails */
-        driversInitialized = false;
-        virStateCleanup();
-    }
-
     virObjectUnref(adminProgram);
     virObjectUnref(srvAdm);
     virObjectUnref(qemuProgram);
@@ -1419,5 +1412,12 @@ int main(int argc, char **argv) {
     VIR_FREE(remote_config_file);
     daemonConfigFree(config);

+    if (driversInitialized) {
+        /* NB: Possible issue with timing window between driversInitialized
+         * setting if virNetlinkEventServerStart fails */
+        driversInitialized = false;
+        virStateCleanup();
+    }
+
     return ret;
 }
--
2.19.1

