Daniel P. Berrange wrote:
The referencing counting code for Connect/Domain/Network
objects has many repeated codepaths, not all of which are
correct. eg, the virFreeDomain method forgets to release
networks when garbage collecting a virConnectPtr, and the
virFreeNetwork method forgets to release domains.
The reference counting in libvirt is not just ugly when interfacing with
a language with real GC, but also broken at the moment.
The most serious example are the connect/domain/network handles included
in a virterror. These are not reference counted so that the caller
doesn't have to free the virterror or these handles. But on the other
hand it means that the handles have an indeterminate lifetime, so cannot
be used safely.
So I've moved the code for garbage collecting a virConnectPtr
object into a new virUnrefConnect() method which can be called
from virFreeConnect, virFreeDomain and virFreeNetwork.
This probably has negative implications in the language bindings. At
this moment I don't care much because network objects are in practice
used only very rarely by real code. This could change when we have
storage objects which, I guess, will be used frequently like domains. A
bit too early in the morning for me to be thinking about GC and its
interaction with reference counting :-)
The rest of the patch looks good. We should probably integrate this
patch in the code right now since (a) it's isolated, (b) it implements
much-needed cleanups, and (c) it needs serious testing.
Rich.
--
Emerging Technologies, Red Hat -
http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in
England and Wales under Company Registration No. 03798903