userlibandfileserver/fileserver/sfile/sf_local.cpp
branchRCL_3
changeset 41 0ffb4e86fcc9
parent 36 bbf8bed59bcb
--- a/userlibandfileserver/fileserver/sfile/sf_local.cpp	Mon Jun 21 17:12:14 2010 +0300
+++ b/userlibandfileserver/fileserver/sfile/sf_local.cpp	Thu Jul 15 20:11:42 2010 +0300
@@ -320,8 +320,31 @@
 	// Create the actual proxy drive...
 	CProxyDrive* pD = NULL;
 	TInt r = pF->CreateProxyDrive(pD, NULL);
-	__ASSERT_ALWAYS(r == KErrNone, User::Panic(_L("CreateProxyDrive Error"), r));
-	__ASSERT_ALWAYS(pD != NULL, User::Panic(_L("CreateProxyDrive returned NULL"), -999));
+	if (r != KErrNone)
+		{
+		delete pD;
+		return r;
+		}
+	if (pD == NULL)
+		return KErrNoMemory;
+
+	// Create the proxy drive body... which is used to store the library handle
+	CProxyDriveBody* pBody = new CProxyDriveBody();
+	if (pBody == NULL)
+		{
+		delete pD;
+		return KErrNoMemory;
+		}
+	pD->iBody = pBody;
+
+	// Re-open the library so that it is safe to call RFs::RemoveProxyDrive() before the proxy drive has been deleted -
+	// which can happen if the file system is dismounted with open file handles
+	r = pD->SetAndOpenLibrary(pF->Library());
+	if (r != KErrNone)
+		{
+		delete pD;
+		return r;
+		}
 
 	iMapping[drive] = i+KMaxLocalDrives;
 
@@ -387,7 +410,11 @@
 	__ASSERT_DEBUG(iMapping[aDrive]>= KMaxLocalDrives && iProxyDriveMapping[iMapping[aDrive]-KMaxLocalDrives],Fault(EClearProxyDriveMapping2));
 	TInt idx = iMapping[aDrive]-KMaxLocalDrives;
 	if (iProxyDriveMapping[idx]->Mount() == NULL)	// don't delete if it's still owned by its mount
+		{
+		RLibrary lib = iProxyDriveMapping[idx]->GetLibrary();
 		delete iProxyDriveMapping[idx];
+		lib.Close();
+		}
 	iProxyDriveMapping[idx] = NULL;
 	iMapping[aDrive] = KDriveInvalid;
 	}