diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 2f0821518337d8ef349973fe1c59721900cb79da..55d00e33dc5801e69d8ba18c113223ebd69b35e3 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -133,14 +133,29 @@ qemuProcessHandleAgentEOF(qemuAgentPtr agent, virObjectLock(vm); priv = vm->privateData; - if (priv->agent == agent && - !virObjectUnref(priv->agent)) - priv->agent = NULL; + + if (!priv->agent) { + VIR_DEBUG("Agent freed already"); + goto unlock; + } + + if (priv->beingDestroyed) { + VIR_DEBUG("Domain is being destroyed, agent EOF is expected"); + goto unlock; + } + + priv->agent = NULL; virObjectUnlock(vm); qemuDriverUnlock(driver); qemuAgentClose(agent); + return; + +unlock: + virObjectUnlock(vm); + qemuDriverUnlock(driver); + return; }