Daniel P. Berrange wrote:
On Mon, Jul 23, 2007 at 05:11:09PM +0100, Richard W.M. Jones wrote:
> This is my test case:
>
> ------------------------------------------
> #!/usr/bin/python
>
> import libvirt
>
> def get_dom():
> conn = libvirt.open ("xen");
> dom = conn.lookupByName ("debian32fv");
> return dom
>
> dom = get_dom()
> print "name = %s\n" % dom.name()
> ------------------------------------------
>
> I would say that it's working as intended.
In this case yes, but if you add one further line at the end of
this example
conn2 = dom.get_connection()
And then have python garbage collect 'dom' and the original 'conn'
you're not safe because 'conn2' didn't increment the reference
count:
I finally managed to reproduce this. For reference, the reproduction
code is below:
--------------------
#!/usr/bin/python
import libvirt
import libvirtmod
def get_dom():
conn = libvirt.open ("xen");
dom = conn.lookupByName ("debian32fv");
return dom
dom = get_dom()
print "name = %s" % dom.name()
conn2 =
libvirt.virConnect (_obj = libvirtmod.virDomainGetConnect (dom._o))
dom2 = conn2.lookupByName ("debian32fv")
--------------------
This crashes at the last line because virConnectClose was called in the
destructor of conn.
It doesn't seem like changing virDomainGetConnect to play with reference
counts will fix this. The damage was done when virConnectClose was
called, which happened much earlier. The only solution is to keep the
relation that domain contains a connection explicit in the Python code.
Same probably applies to OCaml bindings too.
/*
* virDomainGetConnect:
* @dom: pointer to a domain
*
* Provides the connection pointer associated with a domain. The
* reference counter on the connection is not increased by this
* call.
*/
For this reason also I suggest that we remove virDomainGetConnect and
virNetworkGetConnect calls entirely, to prevent anyone from thinking
they can use them in a safe way. Patch is attached, and yes I know in
this case it breaks strict ABI compatibility.
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