diff -r a179b74831c9 -r c1f20ce4abcf userlibandfileserver/fileserver/sfile/sf_thread.cpp --- a/userlibandfileserver/fileserver/sfile/sf_thread.cpp Thu Aug 19 11:14:22 2010 +0300 +++ b/userlibandfileserver/fileserver/sfile/sf_thread.cpp Tue Aug 31 16:34:26 2010 +0300 @@ -925,24 +925,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 */