One of my team mate investigated the issue where libvirt-cim was segfaulting when unloading providers. More info on this issue is at https://www.redhat.com/archives/libvirt-users/2011-August/msg00069.html

Here is the gist of his investigation -


I've looked into the libvirt source code and the reason for issues with the
unload of libvirt-cim providers is there (and cimprovider -r forces an unload,
just as cimserver shutdown does).

virConnectOpen() does call virInitialize() which then will initialize the
gcrypt library after initializes the thread setup ->virThreadInitialize(),
creates the error reporting structure ->virErrorInitialize() and initialize a
random number generator ->virRandomInitialize().

The issue is hidden in virErrorInitialize(). It calls virErrorInitialize()
which uses the wrapper function virThreadLocalInit(&virLastErr,
virLastErrFreeData);.
virThreadLocalInit() calls pthread_create() with a destructor function
(virLastErrFreeData()) which will be called on thread exits.

Trouble here is that pthread_key_delete() is never called in libvirt, but next
time the system runs through the key list and libvirt has been unloaded the
system will jump to an already unloaded function (the pointer were
virLastErrFreeData() was loaded formerly) and consequently crash the process.

Fixing this will not be easy, but a start would be a libvirt function on its
externalize interface that allows cleanup short before library unload, or
alternatively libvirt does the thread key delete on library unload.


Thanks
Sharad Mishra
Open Virtualization
Linux Technology Center
IBM