1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-26 03:21:44 +03:00

libxl: fix leaking libxlDomainObjPrivate

When libxl registers an FD with the libxl driver, the refcnt of the
associated libxlDomainObjPrivate object is incremented. The refcnt
is decremented when libxl deregisters the FD.  But some FDs are only
deregistered when their libxl ctx is freed, which unfortunately is
done in the libxlDomainObjPrivate dispose function.  With references
held by the FDs, libxlDomainObjPrivate is never disposed.

I added the ref/unref in FD registration/deregistration when adding
the same in timer registration/deregistration.  For timers, this
is a simple approach to ensuring the libxlDomainObjPrivate is not
disposed prior to their expirtation, which libxl guarantees will
occur.  It is not needed for FDs, and only causes
libxlDomainObjPrivate to leak.

This patch removes the reference on libxlDomainObjPrivate for FD
registrations, but retains them for timer registrations.  Tested on
the latest releases of Xen supported by the libxl driver:  4.2.3,
4.3.1, and 4.4.0 RC3.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
Jim Fehlig 2014-01-31 16:57:09 -07:00
parent 0778fc1ab9
commit cda52dbfe5

View File

@ -1,7 +1,7 @@
/*
* libxl_domain.c: libxl domain object private state
*
* Copyright (C) 2011-2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
* Copyright (C) 2011-2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -92,7 +92,13 @@ libxlDomainObjPrivateOnceInit(void)
VIR_ONCE_GLOBAL_INIT(libxlDomainObjPrivate)
static void
libxlDomainObjEventHookInfoFree(void *obj)
libxlDomainObjFDEventHookInfoFree(void *obj)
{
VIR_FREE(obj);
}
static void
libxlDomainObjTimerEventHookInfoFree(void *obj)
{
libxlEventHookInfoPtr info = obj;
@ -138,12 +144,6 @@ libxlDomainObjFDRegisterEventHook(void *priv,
return -1;
info->priv = priv;
/*
* Take a reference on the domain object. Reference is dropped in
* libxlDomainObjEventHookInfoFree, ensuring the domain object outlives
* the fd event objects.
*/
virObjectRef(info->priv);
info->xl_priv = xl_priv;
if (events & POLLIN)
@ -152,9 +152,8 @@ libxlDomainObjFDRegisterEventHook(void *priv,
vir_events |= VIR_EVENT_HANDLE_WRITABLE;
info->id = virEventAddHandle(fd, vir_events, libxlDomainObjFDEventCallback,
info, libxlDomainObjEventHookInfoFree);
info, libxlDomainObjFDEventHookInfoFree);
if (info->id < 0) {
virObjectUnref(info->priv);
VIR_FREE(info);
return -1;
}
@ -259,7 +258,7 @@ libxlDomainObjTimeoutRegisterEventHook(void *priv,
timeout = res.tv_sec * 1000 + (res.tv_usec + 999) / 1000;
}
info->id = virEventAddTimeout(timeout, libxlDomainObjTimerCallback,
info, libxlDomainObjEventHookInfoFree);
info, libxlDomainObjTimerEventHookInfoFree);
if (info->id < 0) {
virObjectUnref(info->priv);
VIR_FREE(info);