Bug 1403366 - Don't use nsDirectoryService::Create in nsDirectoryService::GetCurrentProcessDirectory. r?froydnj
Back in the day, there was no global with an already initialized
DirectoryService. But now there is, and, in fact,
GetCurrentProcessDirectory already errors out if that global is not set
by the time it's called. All calling nsDirectoryService::Create achieves
is doing the check again and calling QueryInterface, which we don't need
to do anyways.
--- a/xpcom/io/nsDirectoryService.cpp
+++ b/xpcom/io/nsDirectoryService.cpp
@@ -60,34 +60,22 @@ nsDirectoryService::GetCurrentProcessDir
}
*aFile = nullptr;
// Set the component registry location:
if (!gService) {
return NS_ERROR_FAILURE;
}
- nsresult rv;
-
- nsCOMPtr<nsIProperties> dirService;
- rv = nsDirectoryService::Create(nullptr,
- NS_GET_IID(nsIProperties),
- getter_AddRefs(dirService)); // needs to be around for life of product
- if (NS_FAILED(rv)) {
- return rv;
- }
-
- if (dirService) {
- nsCOMPtr<nsIFile> localFile;
- dirService->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile),
- getter_AddRefs(localFile));
- if (localFile) {
- localFile.forget(aFile);
- return NS_OK;
- }
+ nsCOMPtr<nsIFile> file;
+ gService->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile),
+ getter_AddRefs(file));
+ if (file) {
+ file.forget(aFile);
+ return NS_OK;
}
RefPtr<nsLocalFile> localFile = new nsLocalFile;
#ifdef XP_WIN
wchar_t buf[MAX_PATH + 1];
SetLastError(ERROR_SUCCESS);
if (GetModuleFileNameW(0, buf, mozilla::ArrayLength(buf)) &&
@@ -116,17 +104,17 @@ nsDirectoryService::GetCurrentProcessDir
// This will resolve the relative portion of the CFURL against it base, giving a full
// path, which CFURLCopyFileSystemPath doesn't do.
char buffer[PATH_MAX];
if (CFURLGetFileSystemRepresentation(parentURL, true,
(UInt8*)buffer, sizeof(buffer))) {
#ifdef DEBUG_conrad
printf("nsDirectoryService - CurrentProcessDir is: %s\n", buffer);
#endif
- rv = localFile->InitWithNativePath(nsDependentCString(buffer));
+ nsresult rv = localFile->InitWithNativePath(nsDependentCString(buffer));
if (NS_SUCCEEDED(rv)) {
localFile.forget(aFile);
}
}
CFRelease(parentURL);
}
CFRelease(bundleURL);
}