[libvirt] [PATCH] Fix ref-counting for Xen driver event registration

# HG changeset patch # User john.levon@sun.com # Date 1231958879 28800 # Node ID 46dc909bda5b20d11f08d1516f21c05f27b6648f # Parent 1fca4b0dd4c6ab3c0030b4986de6fe5cb7c94631 Fix ref-counting for Xen driver event registration Signed-off-by: John Levon <john.levon@sun.com> diff --git a/src/xen_unified.c b/src/xen_unified.c --- a/src/xen_unified.c +++ b/src/xen_unified.c @@ -1359,15 +1359,21 @@ xenUnifiedDomainEventRegister (virConnec void *opaque, void (*freefunc)(void *)) { + int ret; + GET_PRIVATE (conn); if (priv->xsWatch == -1) { xenUnifiedError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); return -1; } - conn->refs++; - return virDomainEventCallbackListAdd(conn, priv->domainEventCallbacks, - callback, opaque, freefunc); + ret = virDomainEventCallbackListAdd(conn, priv->domainEventCallbacks, + callback, opaque, freefunc); + + if (ret == 0) + conn->refs++; + + return (ret); } static int @@ -1382,8 +1388,10 @@ xenUnifiedDomainEventDeregister (virConn } ret = virDomainEventCallbackListRemove(conn, priv->domainEventCallbacks, - callback); - virUnrefConnect(conn); + callback); + + if (ret == 0) + virUnrefConnect(conn); return ret; }

john.levon@sun.com wrote:
Fix ref-counting for Xen driver event registration diff --git a/src/xen_unified.c b/src/xen_unified.c --- a/src/xen_unified.c +++ b/src/xen_unified.c @@ -1359,15 +1359,21 @@ xenUnifiedDomainEventRegister (virConnec void *opaque, void (*freefunc)(void *)) { + int ret; + GET_PRIVATE (conn); if (priv->xsWatch == -1) { xenUnifiedError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); return -1; }
- conn->refs++; - return virDomainEventCallbackListAdd(conn, priv->domainEventCallbacks, - callback, opaque, freefunc); + ret = virDomainEventCallbackListAdd(conn, priv->domainEventCallbacks, + callback, opaque, freefunc);
This looks like a fine change, too, but please adjust it not to change the indentation of the above continuation line: ret = virDomainEventCallbackListAdd(conn, priv->domainEventCallbacks, callback, opaque, freefunc);
+ + if (ret == 0) + conn->refs++; + + return (ret); }
static int @@ -1382,8 +1388,10 @@ xenUnifiedDomainEventDeregister (virConn }
ret = virDomainEventCallbackListRemove(conn, priv->domainEventCallbacks, - callback); - virUnrefConnect(conn); + callback);
Same here.

On Wed, Jan 14, 2009 at 10:54:02AM -0800, john.levon@sun.com wrote:
# HG changeset patch # User john.levon@sun.com # Date 1231958879 28800 # Node ID 46dc909bda5b20d11f08d1516f21c05f27b6648f # Parent 1fca4b0dd4c6ab3c0030b4986de6fe5cb7c94631 Fix ref-counting for Xen driver event registration
Signed-off-by: John Levon <john.levon@sun.com>
ACK, based on previous discussion on IRC Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (3)
-
Daniel P. Berrange
-
Jim Meyering
-
john.levon@sun.com