提交 889ce746 编写于 作者: J Jim Fehlig

libxl: Fix race between destruction of objects

It is possible to destroy and cleanup a VM, resulting in freeing the
libxlDomainObjPrivate object and associated libxl ctx, before all fds and
timeouts have been deregistered and destroyed.

Fix this race by incrementing the reference count on libxlDomainObjPrivate
for each fd and timeout registration.  Only when all fds and timeouts are
deregistered and destroyed will the libxlDomainObjPrivate be destroyed.
上级 e0622ca2
...@@ -111,7 +111,11 @@ libxlDriverUnlock(libxlDriverPrivatePtr driver) ...@@ -111,7 +111,11 @@ libxlDriverUnlock(libxlDriverPrivatePtr driver)
static void static void
libxlEventHookInfoFree(void *obj) libxlEventHookInfoFree(void *obj)
{ {
VIR_FREE(obj); libxlEventHookInfoPtr info = obj;
/* Drop reference on libxlDomainObjPrivate */
virObjectUnref(info->priv);
VIR_FREE(info);
} }
static void static void
...@@ -161,6 +165,13 @@ libxlFDRegisterEventHook(void *priv, int fd, void **hndp, ...@@ -161,6 +165,13 @@ libxlFDRegisterEventHook(void *priv, int fd, void **hndp,
} }
info->priv = priv; info->priv = priv;
/*
* Take a reference on the domain object. Reference is dropped in
* libxlEventHookInfoFree, ensuring the domain object outlives the fd
* event objects.
*/
virObjectRef(info->priv);
info->xl_priv = xl_priv; info->xl_priv = xl_priv;
*hndp = info; *hndp = info;
...@@ -257,6 +268,13 @@ libxlTimeoutRegisterEventHook(void *priv, ...@@ -257,6 +268,13 @@ libxlTimeoutRegisterEventHook(void *priv,
} }
info->priv = priv; info->priv = priv;
/*
* Also take a reference on the domain object. Reference is dropped in
* libxlEventHookInfoFree, ensuring the domain object outlives the timeout
* event objects.
*/
virObjectRef(info->priv);
info->xl_priv = xl_priv; info->xl_priv = xl_priv;
*hndp = info; *hndp = info;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册