зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1343866
- Scope more nsCOMPtrs in XRE_XPCShellMain(); r=bsmedberg
This commit is contained in:
Родитель
e69291f9ae
Коммит
65b2fe2b53
|
@ -1323,115 +1323,115 @@ XRE_XPCShellMain(int argc, char** argv, char** envp,
|
|||
printf_stderr("*** You are running in chaos test mode. See ChaosMode.h. ***\n");
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> appFile;
|
||||
rv = XRE_GetBinaryPath(argv[0], getter_AddRefs(appFile));
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("Couldn't find application file.\n");
|
||||
return 1;
|
||||
}
|
||||
nsCOMPtr<nsIFile> appDir;
|
||||
rv = appFile->GetParent(getter_AddRefs(appDir));
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("Couldn't get application directory.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
XPCShellDirProvider dirprovider;
|
||||
|
||||
dirprovider.SetAppFile(appFile);
|
||||
|
||||
nsCOMPtr<nsIFile> greDir;
|
||||
if (argc > 1 && !strcmp(argv[1], "-g")) {
|
||||
if (argc < 3)
|
||||
return usage();
|
||||
|
||||
rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(greDir));
|
||||
{ // Start scoping nsCOMPtrs
|
||||
nsCOMPtr<nsIFile> appFile;
|
||||
rv = XRE_GetBinaryPath(argv[0], getter_AddRefs(appFile));
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("Couldn't use given GRE dir.\n");
|
||||
printf("Couldn't find application file.\n");
|
||||
return 1;
|
||||
}
|
||||
nsCOMPtr<nsIFile> appDir;
|
||||
rv = appFile->GetParent(getter_AddRefs(appDir));
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("Couldn't get application directory.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
dirprovider.SetGREDirs(greDir);
|
||||
XPCShellDirProvider dirprovider;
|
||||
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
} else {
|
||||
dirprovider.SetAppFile(appFile);
|
||||
|
||||
nsCOMPtr<nsIFile> greDir;
|
||||
if (argc > 1 && !strcmp(argv[1], "-g")) {
|
||||
if (argc < 3)
|
||||
return usage();
|
||||
|
||||
rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(greDir));
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("Couldn't use given GRE dir.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
dirprovider.SetGREDirs(greDir);
|
||||
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
} else {
|
||||
#ifdef XP_MACOSX
|
||||
// On OSX, the GreD needs to point to Contents/Resources in the .app
|
||||
// bundle. Libraries will be loaded at a relative path to GreD, i.e.
|
||||
// ../MacOS.
|
||||
nsCOMPtr<nsIFile> tmpDir;
|
||||
XRE_GetFileFromPath(argv[0], getter_AddRefs(greDir));
|
||||
greDir->GetParent(getter_AddRefs(tmpDir));
|
||||
tmpDir->Clone(getter_AddRefs(greDir));
|
||||
tmpDir->SetNativeLeafName(NS_LITERAL_CSTRING("Resources"));
|
||||
bool dirExists = false;
|
||||
tmpDir->Exists(&dirExists);
|
||||
if (dirExists) {
|
||||
greDir = tmpDir.forget();
|
||||
}
|
||||
dirprovider.SetGREDirs(greDir);
|
||||
// On OSX, the GreD needs to point to Contents/Resources in the .app
|
||||
// bundle. Libraries will be loaded at a relative path to GreD, i.e.
|
||||
// ../MacOS.
|
||||
nsCOMPtr<nsIFile> tmpDir;
|
||||
XRE_GetFileFromPath(argv[0], getter_AddRefs(greDir));
|
||||
greDir->GetParent(getter_AddRefs(tmpDir));
|
||||
tmpDir->Clone(getter_AddRefs(greDir));
|
||||
tmpDir->SetNativeLeafName(NS_LITERAL_CSTRING("Resources"));
|
||||
bool dirExists = false;
|
||||
tmpDir->Exists(&dirExists);
|
||||
if (dirExists) {
|
||||
greDir = tmpDir.forget();
|
||||
}
|
||||
dirprovider.SetGREDirs(greDir);
|
||||
#else
|
||||
nsAutoString workingDir;
|
||||
if (!GetCurrentWorkingDirectory(workingDir)) {
|
||||
printf("GetCurrentWorkingDirectory failed.\n");
|
||||
return 1;
|
||||
}
|
||||
rv = NS_NewLocalFile(workingDir, true, getter_AddRefs(greDir));
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("NS_NewLocalFile failed.\n");
|
||||
return 1;
|
||||
}
|
||||
nsAutoString workingDir;
|
||||
if (!GetCurrentWorkingDirectory(workingDir)) {
|
||||
printf("GetCurrentWorkingDirectory failed.\n");
|
||||
return 1;
|
||||
}
|
||||
rv = NS_NewLocalFile(workingDir, true, getter_AddRefs(greDir));
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("NS_NewLocalFile failed.\n");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (argc > 1 && !strcmp(argv[1], "-a")) {
|
||||
if (argc < 3)
|
||||
return usage();
|
||||
|
||||
nsCOMPtr<nsIFile> dir;
|
||||
rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(dir));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
appDir = do_QueryInterface(dir, &rv);
|
||||
dirprovider.SetAppDir(appDir);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("Couldn't use given appdir.\n");
|
||||
return 1;
|
||||
|
||||
if (argc > 1 && !strcmp(argv[1], "-a")) {
|
||||
if (argc < 3)
|
||||
return usage();
|
||||
|
||||
nsCOMPtr<nsIFile> dir;
|
||||
rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(dir));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
appDir = do_QueryInterface(dir, &rv);
|
||||
dirprovider.SetAppDir(appDir);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("Couldn't use given appdir.\n");
|
||||
return 1;
|
||||
}
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
}
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
}
|
||||
|
||||
while (argc > 1 && !strcmp(argv[1], "-r")) {
|
||||
if (argc < 3)
|
||||
return usage();
|
||||
while (argc > 1 && !strcmp(argv[1], "-r")) {
|
||||
if (argc < 3)
|
||||
return usage();
|
||||
|
||||
nsCOMPtr<nsIFile> lf;
|
||||
rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(lf));
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("Couldn't get manifest file.\n");
|
||||
return 1;
|
||||
nsCOMPtr<nsIFile> lf;
|
||||
rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(lf));
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("Couldn't get manifest file.\n");
|
||||
return 1;
|
||||
}
|
||||
XRE_AddManifestLocation(NS_APP_LOCATION, lf);
|
||||
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
}
|
||||
XRE_AddManifestLocation(NS_APP_LOCATION, lf);
|
||||
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
}
|
||||
|
||||
#ifdef MOZ_CRASHREPORTER
|
||||
const char* val = getenv("MOZ_CRASHREPORTER");
|
||||
if (val && *val) {
|
||||
rv = CrashReporter::SetExceptionHandler(greDir, true);
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("CrashReporter::SetExceptionHandler failed!\n");
|
||||
return 1;
|
||||
const char* val = getenv("MOZ_CRASHREPORTER");
|
||||
if (val && *val) {
|
||||
rv = CrashReporter::SetExceptionHandler(greDir, true);
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("CrashReporter::SetExceptionHandler failed!\n");
|
||||
return 1;
|
||||
}
|
||||
MOZ_ASSERT(CrashReporter::GetEnabled());
|
||||
}
|
||||
MOZ_ASSERT(CrashReporter::GetEnabled());
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
if (argc > 1 && !strcmp(argv[1], "--greomni")) {
|
||||
nsCOMPtr<nsIFile> greOmni;
|
||||
nsCOMPtr<nsIFile> appOmni;
|
||||
|
@ -1626,6 +1626,11 @@ XRE_XPCShellMain(int argc, char** argv, char** envp,
|
|||
JS_GC(cx);
|
||||
}
|
||||
JS_GC(cx);
|
||||
|
||||
dirprovider.ClearGREDirs();
|
||||
dirprovider.ClearAppDir();
|
||||
dirprovider.ClearPluginDir();
|
||||
dirprovider.ClearAppFile();
|
||||
} // this scopes the nsCOMPtrs
|
||||
|
||||
if (!XRE_ShutdownTestShell())
|
||||
|
@ -1643,12 +1648,6 @@ XRE_XPCShellMain(int argc, char** argv, char** envp,
|
|||
#endif
|
||||
|
||||
telStats = nullptr;
|
||||
appDir = nullptr;
|
||||
appFile = nullptr;
|
||||
dirprovider.ClearGREDirs();
|
||||
dirprovider.ClearAppDir();
|
||||
dirprovider.ClearPluginDir();
|
||||
dirprovider.ClearAppFile();
|
||||
|
||||
#ifdef MOZ_CRASHREPORTER
|
||||
// Shut down the crashreporter service to prevent leaking some strings it holds.
|
||||
|
|
Загрузка…
Ссылка в новой задаче