diff -r 657f875b013e -r 73ea206103e6 userlibandfileserver/fileserver/sfile/sf_thread.cpp --- a/userlibandfileserver/fileserver/sfile/sf_thread.cpp Fri Jun 11 15:02:23 2010 +0300 +++ b/userlibandfileserver/fileserver/sfile/sf_thread.cpp Wed Jun 23 19:44:53 2010 +0300 @@ -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 */