diff -r 5e441a173c63 -r d9f1e5bfe28c userlibandfileserver/fileserver/sfile/sf_thread.cpp --- a/userlibandfileserver/fileserver/sfile/sf_thread.cpp Mon May 24 18:45:46 2010 +0100 +++ b/userlibandfileserver/fileserver/sfile/sf_thread.cpp Thu Jun 10 11:48:01 2010 +0100 @@ -926,24 +926,34 @@ } -CPluginThread::CPluginThread(CFsPlugin& aPlugin) - : iPlugin(aPlugin) +CPluginThread::CPluginThread(CFsPlugin& aPlugin, RLibrary aLibrary) + : iPlugin(aPlugin), iLib(aLibrary) { /** @prototype */ iOperationLock.Close(); iPlugin.Open(); + + /* + Duplicate the handle to the DLL which created the plugin to prevent + TFsRemovePlugin::DoRequestL() from unmapping the DLL's code segment before + this thread's destructor has been called as the destructor closes the plugin + which results in a call to the plugin's derived destructor contained in the DLL (!) + */ + TInt r = iLib.Duplicate(iThread, EOwnerProcess); + __ASSERT_ALWAYS(r==KErrNone, Fault(EFsThreadConstructor)); } CPluginThread::~CPluginThread() { iPlugin.Close(); + iLib.Close(); } -CPluginThread* CPluginThread::NewL(CFsPlugin& aPlugin) +CPluginThread* CPluginThread::NewL(CFsPlugin& aPlugin, RLibrary aLibrary) { __PRINT(_L("CPluginThread::NewL()")); - CPluginThread* pT=new(ELeave) CPluginThread(aPlugin); + CPluginThread* pT=new(ELeave) CPluginThread(aPlugin, aLibrary); TInt r=pT->Initialise(); /** @prototype */