From: Michal Privoznik Date: Thu, 18 Jun 2015 12:37:43 +0000 (+0200) Subject: virNetServerServiceClose: Don't leak sockets X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=355d8f470f92f10587bb84709fddb706efdb4dee;p=people%2Fliuw%2Flibxenctrl-split%2Flibvirt.git virNetServerServiceClose: Don't leak sockets Well, if a server is being destructed, all underlying services and their sockets should disappear with it. But due to bug in our implementation this is not the case. Yes, we are closing the sockets, but that's not enough. We must also: 1) Unregister them from the event loop 2) Unref the service for each socket The last step is needed, because each socket callback holds a reference to the service object. Since in the first step we are unregistering the callbacks, they no longer need the reference. Signed-off-by: Michal Privoznik --- diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index 4df26cb52..3b35fc092 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -520,6 +520,9 @@ void virNetServerServiceClose(virNetServerServicePtr svc) if (!svc) return; - for (i = 0; i < svc->nsocks; i++) + for (i = 0; i < svc->nsocks; i++) { + virNetSocketRemoveIOCallback(svc->socks[i]); virNetSocketClose(svc->socks[i]); + virObjectUnref(svc); + } }