]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
fix a bug of ref count in virnetserver.c
authorHu Tao <hutao@cn.fujitsu.com>
Fri, 22 Jun 2012 03:26:03 +0000 (11:26 +0800)
committerJim Fehlig <jfehlig@suse.com>
Fri, 22 Jun 2012 18:13:42 +0000 (12:13 -0600)
The test of ref count is not protected by lock, which is unsafe because
the ref count may have been changed by other threads during the test.

This patch fixes this.

src/rpc/virnetserver.c

index 9d71e53698b29ed7aec10c03fe41e65e39bc2d07..247ddd75854b11bd601b202a5f4b7e7fb650dc08 100644 (file)
@@ -759,15 +759,16 @@ void virNetServerQuit(virNetServerPtr srv)
 void virNetServerFree(virNetServerPtr srv)
 {
     int i;
+    int refs;
 
     if (!srv)
         return;
 
     virNetServerLock(srv);
     VIR_DEBUG("srv=%p refs=%d", srv, srv->refs);
-    srv->refs--;
+    refs = --srv->refs;
     virNetServerUnlock(srv);
-    if (srv->refs > 0)
+    if (refs > 0)
         return;
 
     for (i = 0 ; i < srv->nservices ; i++)