<html><body>
<p><tt>One of my team mate investigated the issue where libvirt-cim was segfaulting when unloading providers. More info on this issue is at </tt><tt><a href="https://www.redhat.com/archives/libvirt-users/2011-August/msg00069.html">https://www.redhat.com/archives/libvirt-users/2011-August/msg00069.html</a></tt><br>
<br>
<tt>Here is the gist of his investigation -</tt><br>
<br>
<br>
<tt>I've looked into the libvirt source code and the reason for issues with the<br>
unload of libvirt-cim providers is there (and cimprovider -r forces an unload,<br>
just as cimserver shutdown does).<br>
<br>
virConnectOpen() does call virInitialize() which then will initialize the<br>
gcrypt library after initializes the thread setup ->virThreadInitialize(),<br>
creates the error reporting structure ->virErrorInitialize() and initialize a<br>
random number generator ->virRandomInitialize().<br>
<br>
The issue is hidden in virErrorInitialize(). It calls virErrorInitialize()<br>
which uses the wrapper function virThreadLocalInit(&virLastErr,<br>
virLastErrFreeData);.<br>
virThreadLocalInit() calls pthread_create() with a destructor function<br>
(virLastErrFreeData()) which will be called on thread exits.<br>
<br>
Trouble here is that pthread_key_delete() is never called in libvirt, but next<br>
time the system runs through the key list and libvirt has been unloaded the<br>
system will jump to an already unloaded function (the pointer were<br>
virLastErrFreeData() was loaded formerly) and consequently crash the process.<br>
<br>
Fixing this will not be easy, but a start would be a libvirt function on its<br>
externalize interface that allows cleanup short before library unload, or<br>
alternatively libvirt does the thread key delete on library unload.</tt><br>
<br>
<tt>Thanks</tt><br>
Sharad Mishra<br>
Open Virtualization<br>
Linux Technology Center<br>
IBM</body></html>