Delete gVolumeList on shutdown. b=397305 r+sr+a1.9=bzbarsky

This commit is contained in:
dbaron@dbaron.org 2007-10-02 15:26:53 -07:00
parent 4ef1943bb5
commit c5d13d4123
3 changed files with 25 additions and 5 deletions

View File

@ -67,6 +67,9 @@ enum netCoalesceFlags
/* shutdown frees URL parser */
NS_HIDDEN_(void) net_ShutdownURLHelper();
#ifdef XP_MACOSX
NS_HIDDEN_(void) net_ShutdownURLHelperOSX();
#endif
/* access URL parsers */
NS_HIDDEN_(nsIURLParser *) net_GetAuthURLParser();

View File

@ -39,7 +39,7 @@
*
* ***** END LICENSE BLOCK ***** */
/* Unix-specific local file uri parsing */
/* Mac OS X-specific local file uri parsing */
#include "nsURLHelper.h"
#include "nsEscape.h"
#include "nsILocalFile.h"
@ -47,6 +47,8 @@
#include "nsReadableUtils.h"
#include <Files.h>
static nsCStringArray *gVolumeList = nsnull;
static PRBool pathBeginsWithVolName(const nsACString& path, nsACString& firstPathComponent)
{
// Return whether the 1st path component in path (escaped) is equal to the name
@ -54,10 +56,15 @@ static PRBool pathBeginsWithVolName(const nsACString& path, nsACString& firstPat
// This needs to be done as quickly as possible, so we cache a list of volume names.
// XXX Register an event handler to detect drives being mounted/unmounted?
static nsCStringArray gVolumeList; // We will leak this - one for the life of the app :-/
if (!gVolumeList) {
gVolumeList = new nsCStringArray;
if (!gVolumeList) {
return PR_FALSE; // out of memory
}
}
// Cache a list of volume names
if (!gVolumeList.Count()) {
if (!gVolumeList->Count()) {
OSErr err;
ItemCount volumeIndex = 1;
@ -68,7 +75,7 @@ static PRBool pathBeginsWithVolName(const nsACString& path, nsACString& firstPat
if (err == noErr) {
NS_ConvertUTF16toUTF8 volNameStr(Substring((PRUnichar *)volName.unicode,
(PRUnichar *)volName.unicode + volName.length));
gVolumeList.AppendCString(volNameStr);
gVolumeList->AppendCString(volNameStr);
volumeIndex++;
}
} while (err == noErr);
@ -85,11 +92,18 @@ static PRBool pathBeginsWithVolName(const nsACString& path, nsACString& firstPat
nsCAutoString flatComponent((Substring(start, component_end)));
NS_UnescapeURL(flatComponent);
PRInt32 foundIndex = gVolumeList.IndexOf(flatComponent);
PRInt32 foundIndex = gVolumeList->IndexOf(flatComponent);
firstPathComponent = flatComponent;
return (foundIndex != -1);
}
void
net_ShutdownURLHelperOSX()
{
delete gVolumeList;
gVolumeList = nsnull;
}
static nsresult convertHFSPathtoPOSIX(const nsACString& hfsPath, nsACString& posixPath)
{
// Use CFURL to do the conversion. We don't want to do this by simply

View File

@ -605,6 +605,9 @@ static void PR_CALLBACK nsNetShutdown(nsIModule *neckoModule)
// Release global state used by the URL helper module.
net_ShutdownURLHelper();
#ifdef XP_MACOSX
net_ShutdownURLHelperOSX();
#endif
// Release necko strings
delete gNetStrings;