[libvirt] "invalid connection pointer in virConnectClose" from Python bindings

Daniel P. Berrange berrange at redhat.com
Mon Mar 30 09:24:58 UTC 2009

On Sun, Mar 29, 2009 at 11:36:36PM -0500, Charles Duffy wrote:
> Howdy.
> I'm calling libvirt from a program which occasionally has cause to 
> fork() without an immediate exec(). For the sake of simplicity, I 
> presently call close() on all my virConnect objects [which I then 
> delete] before forking and create new ones later. (I'm not forcing an 
> explicit pre-fork garbage collection at present -- hopefully the close() 
> should make one unnecessary).
> However, libvirt complains (and very occasionally segfaults) as I try to 
> close the connections:
> libvir: error : invalid connection pointer in virConnectClose
> libvir: error : invalid connection pointer in virConnectClose
> Are there any practices I should be following to avoid this? 
> Alternatively, if it is likely to be related to an issue in the Python 
> bindings, is there something I could do to diagnose?

What I think is going on here is:

 - You explicitly called 'close()' which calls virConnectClose() which releases
the underlying virConnectPtr object

 - Garbage collection later invokes __del__, which tries to call
virConnectClose too. 

The 2nd scenario causes the error message you see. We need to fix the __del__
method, so it only calls virConnectClose(), if the user has not already done

|: 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 :|

More information about the libvir-list mailing list