Bug 1874226 - Use unique_ptr not Scoped in xpcom/*. r=xpcom-reviewers,necko-reviewers,valentin,emilio

Differential Revision: https://phabricator.services.mozilla.com/D200250
This commit is contained in:
Kelsey Gilbert 2024-02-07 18:30:22 +00:00
parent b2be0b2dcd
commit 34cdfc4f86
17 changed files with 75 additions and 106 deletions

View file

@ -4175,12 +4175,12 @@ nsresult ArrayBufferBuilder::MapToFileInPackage(const nsCString& aFile,
uint32_t offset = zip->GetDataOffset(zipItem); uint32_t offset = zip->GetDataOffset(zipItem);
uint32_t size = zipItem->RealSize(); uint32_t size = zipItem->RealSize();
mozilla::AutoFDClose pr_fd; mozilla::AutoFDClose pr_fd;
rv = aJarFile->OpenNSPRFileDesc(PR_RDONLY, 0, &pr_fd.rwget()); rv = aJarFile->OpenNSPRFileDesc(PR_RDONLY, 0, getter_Transfers(pr_fd));
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return rv; return rv;
} }
mMapPtr = JS::CreateMappedArrayBufferContents( mMapPtr = JS::CreateMappedArrayBufferContents(
PR_FileDesc2NativeHandle(pr_fd), offset, size); PR_FileDesc2NativeHandle(pr_fd.get()), offset, size);
if (mMapPtr) { if (mMapPtr) {
mLength = size; mLength = size;
return NS_OK; return NS_OK;

View file

@ -34,7 +34,7 @@ Result<Ok, nsresult> AutoMemMap::init(nsIFile* file, int flags, int mode,
PRFileMapProtect prot) { PRFileMapProtect prot) {
MOZ_ASSERT(!fd); MOZ_ASSERT(!fd);
MOZ_TRY(file->OpenNSPRFileDesc(flags, mode, &fd.rwget())); MOZ_TRY(file->OpenNSPRFileDesc(flags, mode, getter_Transfers(fd)));
return initInternal(prot); return initInternal(prot);
} }
@ -48,7 +48,7 @@ Result<Ok, nsresult> AutoMemMap::init(const FileDescriptor& file,
auto handle = file.ClonePlatformHandle(); auto handle = file.ClonePlatformHandle();
fd = PR_ImportFile(PROsfd(handle.get())); fd.reset(PR_ImportFile(PROsfd(handle.get())));
if (!fd) { if (!fd) {
return Err(NS_ERROR_FAILURE); return Err(NS_ERROR_FAILURE);
} }
@ -79,7 +79,7 @@ Result<Ok, nsresult> AutoMemMap::initInternal(PRFileMapProtect prot,
size_ = fileInfo.size; size_ = fileInfo.size;
} }
fileMap = PR_CreateFileMap(fd, 0, prot); fileMap = PR_CreateFileMap(fd.get(), 0, prot);
if (!fileMap) { if (!fileMap) {
return Err(NS_ERROR_FAILURE); return Err(NS_ERROR_FAILURE);
} }
@ -151,7 +151,7 @@ void AutoMemMap::reset() {
handle_ = nullptr; handle_ = nullptr;
} }
#endif #endif
fd.dispose(); fd = nullptr;
} }
} // namespace loader } // namespace loader

View file

@ -712,9 +712,10 @@ Result<Ok, nsresult> ScriptPreloader::WriteCache() {
} }
{ {
AutoFDClose fd; AutoFDClose raiiFd;
MOZ_TRY(cacheFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, 0644, MOZ_TRY(cacheFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, 0644,
&fd.rwget())); getter_Transfers(raiiFd)));
const auto fd = raiiFd.get();
// We also need to hold mMonitor while we're touching scripts in // We also need to hold mMonitor while we're touching scripts in
// mScripts, or they may be freed before we're done with them. // mScripts, or they may be freed before we're done with them.

View file

@ -222,9 +222,10 @@ Result<Ok, nsresult> URLPreloader::WriteCache() {
} }
{ {
AutoFDClose fd; AutoFDClose raiiFd;
MOZ_TRY(cacheFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, 0644, MOZ_TRY(cacheFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, 0644,
&fd.rwget())); getter_Transfers(raiiFd)));
const auto fd = raiiFd.get();
nsTArray<URLEntry*> entries; nsTArray<URLEntry*> entries;
for (const auto& entry : mCachedURLs.Values()) { for (const auto& entry : mCachedURLs.Values()) {

View file

@ -190,13 +190,13 @@ nsresult nsZipHandle::Init(nsIFile* file, nsZipHandle** ret, PRFileDesc** aFd) {
flags |= nsIFile::OS_READAHEAD; flags |= nsIFile::OS_READAHEAD;
#endif #endif
LOG(("ZipHandle::Init %s", file->HumanReadablePath().get())); LOG(("ZipHandle::Init %s", file->HumanReadablePath().get()));
nsresult rv = file->OpenNSPRFileDesc(flags, 0000, &fd.rwget()); nsresult rv = file->OpenNSPRFileDesc(flags, 0000, getter_Transfers(fd));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
int64_t size = PR_Available64(fd); int64_t size = PR_Available64(fd.get());
if (size >= INT32_MAX) return NS_ERROR_FILE_TOO_BIG; if (size >= INT32_MAX) return NS_ERROR_FILE_TOO_BIG;
PRFileMap* map = PR_CreateFileMap(fd, size, PR_PROT_READONLY); PRFileMap* map = PR_CreateFileMap(fd.get(), size, PR_PROT_READONLY);
if (!map) return NS_ERROR_FAILURE; if (!map) return NS_ERROR_FAILURE;
uint8_t* buf = (uint8_t*)PR_MemMap(map, 0, (uint32_t)size); uint8_t* buf = (uint8_t*)PR_MemMap(map, 0, (uint32_t)size);
@ -216,10 +216,10 @@ nsresult nsZipHandle::Init(nsIFile* file, nsZipHandle** ret, PRFileDesc** aFd) {
#if defined(XP_WIN) #if defined(XP_WIN)
if (aFd) { if (aFd) {
*aFd = fd.forget(); *aFd = fd.release();
} }
#else #else
handle->mNSPRFileDesc = fd.forget(); handle->mNSPRFileDesc = std::move(fd);
#endif #endif
handle->mFile.Init(file); handle->mFile.Init(file);
handle->mTotalLen = (uint32_t)size; handle->mTotalLen = (uint32_t)size;
@ -344,7 +344,7 @@ nsresult nsZipHandle::GetNSPRFileDesc(PRFileDesc** aNSPRFileDesc) {
return NS_ERROR_ILLEGAL_VALUE; return NS_ERROR_ILLEGAL_VALUE;
} }
*aNSPRFileDesc = mNSPRFileDesc; *aNSPRFileDesc = mNSPRFileDesc.get();
if (!mNSPRFileDesc) { if (!mNSPRFileDesc) {
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
} }
@ -387,7 +387,8 @@ already_AddRefed<nsZipArchive> nsZipArchive::OpenArchive(nsIFile* aFile) {
RefPtr<nsZipHandle> handle; RefPtr<nsZipHandle> handle;
#if defined(XP_WIN) #if defined(XP_WIN)
mozilla::AutoFDClose fd; mozilla::AutoFDClose fd;
nsresult rv = nsZipHandle::Init(aFile, getter_AddRefs(handle), &fd.rwget()); nsresult rv =
nsZipHandle::Init(aFile, getter_AddRefs(handle), getter_Transfers(fd));
#else #else
nsresult rv = nsZipHandle::Init(aFile, getter_AddRefs(handle)); nsresult rv = nsZipHandle::Init(aFile, getter_AddRefs(handle));
#endif #endif

View file

@ -186,15 +186,16 @@ class ExtensionJARFileOpener final : public nsISupports {
MOZ_ASSERT(winFile); MOZ_ASSERT(winFile);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = winFile->OpenNSPRFileDescShareDelete(PR_RDONLY, 0, rv = winFile->OpenNSPRFileDescShareDelete(PR_RDONLY, 0,
&prFileDesc.rwget()); getter_Transfers(prFileDesc));
} }
#else #else
nsresult rv = mFile->OpenNSPRFileDesc(PR_RDONLY, 0, &prFileDesc.rwget()); nsresult rv =
mFile->OpenNSPRFileDesc(PR_RDONLY, 0, getter_Transfers(prFileDesc));
#endif /* XP_WIN */ #endif /* XP_WIN */
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
mFD = FileDescriptor(FileDescriptor::PlatformHandleType( mFD = FileDescriptor(FileDescriptor::PlatformHandleType(
PR_FileDesc2NativeHandle(prFileDesc))); PR_FileDesc2NativeHandle(prFileDesc.get())));
} }
nsCOMPtr<nsIRunnable> event = nsCOMPtr<nsIRunnable> event =

View file

@ -522,9 +522,10 @@ Result<Ok, nsresult> StartupCache::WriteToDisk() {
return Err(NS_ERROR_UNEXPECTED); return Err(NS_ERROR_UNEXPECTED);
} }
AutoFDClose fd; AutoFDClose raiiFd;
MOZ_TRY(mFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, MOZ_TRY(mFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
0644, &fd.rwget())); 0644, getter_Transfers(raiiFd)));
const auto fd = raiiFd.get();
nsTArray<StartupCacheEntry::KeyValuePair> entries(mTable.count()); nsTArray<StartupCacheEntry::KeyValuePair> entries(mTable.count());
for (auto iter = mTable.iter(); !iter.done(); iter.next()) { for (auto iter = mTable.iter(); !iter.done(); iter.next()) {

View file

@ -10,6 +10,7 @@
#include "nsPrintfCString.h" #include "nsPrintfCString.h"
#include "js/Array.h" // JS::NewArrayObject #include "js/Array.h" // JS::NewArrayObject
#include "js/PropertyAndElement.h" // JS_DefineElement #include "js/PropertyAndElement.h" // JS_DefineElement
#include "mozilla/FileUtils.h"
#include "mozilla/gfx/GPUParent.h" #include "mozilla/gfx/GPUParent.h"
#include "mozilla/dom/ContentChild.h" #include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h" // For RemoteTypePrefix #include "mozilla/dom/ContentParent.h" // For RemoteTypePrefix
@ -576,8 +577,10 @@ Result<Ok, nsresult> ReadEntry(PRFileDesc* aFile, HangStack& aStack) {
} }
Result<HangDetails, nsresult> ReadHangDetailsFromFile(nsIFile* aFile) { Result<HangDetails, nsresult> ReadHangDetailsFromFile(nsIFile* aFile) {
AutoFDClose fd; AutoFDClose raiiFd;
nsresult rv = aFile->OpenNSPRFileDesc(PR_RDONLY, 0644, &fd.rwget()); nsresult rv =
aFile->OpenNSPRFileDesc(PR_RDONLY, 0644, getter_Transfers(raiiFd));
const auto fd = raiiFd.get();
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return Err(rv); return Err(rv);
} }
@ -650,9 +653,11 @@ Result<Ok, nsresult> WriteHangDetailsToFile(HangDetails& aDetails,
return Err(NS_ERROR_INVALID_POINTER); return Err(NS_ERROR_INVALID_POINTER);
} }
AutoFDClose fd; AutoFDClose raiiFd;
nsresult rv = aFile->OpenNSPRFileDesc( nsresult rv = aFile->OpenNSPRFileDesc(
PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0644, &fd.rwget()); PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0644, getter_Transfers(raiiFd));
const auto fd = raiiFd.get();
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return Err(rv); return Err(rv);
} }

View file

@ -4553,7 +4553,7 @@ bool XREMain::CheckLastStartupWasCrash() {
// the startup crash detection window. // the startup crash detection window.
AutoFDClose fd; AutoFDClose fd;
Unused << crashFile.inspect()->OpenNSPRFileDesc( Unused << crashFile.inspect()->OpenNSPRFileDesc(
PR_WRONLY | PR_CREATE_FILE | PR_EXCL, 0666, &fd.rwget()); PR_WRONLY | PR_CREATE_FILE | PR_EXCL, 0666, getter_Transfers(fd));
return !fd; return !fd;
} }

View file

@ -122,7 +122,7 @@ bool GetLSBRelease(nsACString& aDistributor, nsACString& aDescription,
} }
char dist[256], desc[256], release[256], codename[256]; char dist[256], desc[256], release[256], codename[256];
if (fscanf(stream, if (fscanf(stream.get(),
"Distributor ID:\t%255[^\n]\n" "Distributor ID:\t%255[^\n]\n"
"Description:\t%255[^\n]\n" "Description:\t%255[^\n]\n"
"Release:\t%255[^\n]\n" "Release:\t%255[^\n]\n"

View file

@ -268,7 +268,7 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader* aLoader,
mozilla::AutoFDClose fd; mozilla::AutoFDClose fd;
rv = canberraFile->OpenNSPRFileDesc(PR_WRONLY, PR_IRUSR | PR_IWUSR, rv = canberraFile->OpenNSPRFileDesc(PR_WRONLY, PR_IRUSR | PR_IWUSR,
&fd.rwget()); getter_Transfers(fd));
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return rv; return rv;
} }
@ -276,7 +276,7 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader* aLoader,
// XXX: Should we do this on another thread? // XXX: Should we do this on another thread?
uint32_t length = dataLen; uint32_t length = dataLen;
while (length > 0) { while (length > 0) {
int32_t amount = PR_Write(fd, data, length); int32_t amount = PR_Write(fd.get(), data, length);
if (amount < 0) { if (amount < 0) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

View file

@ -176,14 +176,14 @@ bool LimitFileToLessThanSize(const char* aFilename, uint32_t aSize,
return false; return false;
} }
if (fseek(file, 0, SEEK_END)) { if (fseek(file.get(), 0, SEEK_END)) {
// If we can't seek for some reason, better to just not limit the log at // If we can't seek for some reason, better to just not limit the log at
// all and hope to sort out large logs upon further analysis. // all and hope to sort out large logs upon further analysis.
return false; return false;
} }
// `ftell` returns a positive `long`, which might be more than 32 bits. // `ftell` returns a positive `long`, which might be more than 32 bits.
uint64_t fileSize = static_cast<uint64_t>(ftell(file)); uint64_t fileSize = static_cast<uint64_t>(ftell(file.get()));
if (fileSize <= aSize) { if (fileSize <= aSize) {
return true; return true;
@ -192,7 +192,7 @@ bool LimitFileToLessThanSize(const char* aFilename, uint32_t aSize,
uint64_t minBytesToDrop = fileSize - aSize; uint64_t minBytesToDrop = fileSize - aSize;
uint64_t numBytesDropped = 0; uint64_t numBytesDropped = 0;
if (fseek(file, 0, SEEK_SET)) { if (fseek(file.get(), 0, SEEK_SET)) {
// Same as above: if we can't seek, hope for the best. // Same as above: if we can't seek, hope for the best.
return false; return false;
} }
@ -250,11 +250,12 @@ bool LimitFileToLessThanSize(const char* aFilename, uint32_t aSize,
// `fgets` always null terminates. If the line is too long, it won't // `fgets` always null terminates. If the line is too long, it won't
// include a trailing '\n' but will be null-terminated. // include a trailing '\n' but will be null-terminated.
UniquePtr<char[]> line = MakeUnique<char[]>(aLongLineSize + 1); UniquePtr<char[]> line = MakeUnique<char[]>(aLongLineSize + 1);
while (fgets(line.get(), aLongLineSize + 1, file)) { while (fgets(line.get(), aLongLineSize + 1, file.get())) {
if (numBytesDropped >= minBytesToDrop) { if (numBytesDropped >= minBytesToDrop) {
if (fputs(line.get(), temp) < 0) { if (fputs(line.get(), temp.get()) < 0) {
NS_WARNING( NS_WARNING(
nsPrintfCString("fputs failed: ferror %d\n", ferror(temp)).get()); nsPrintfCString("fputs failed: ferror %d\n", ferror(temp.get()))
.get());
failedToWrite = true; failedToWrite = true;
break; break;
} }

View file

@ -8,6 +8,8 @@
#include "nsZipArchive.h" #include "nsZipArchive.h"
#include "nsURLHelper.h" #include "nsURLHelper.h"
#include "mozilla/UniquePtrExtensions.h"
namespace mozilla { namespace mozilla {
FileLocation::FileLocation() = default; FileLocation::FileLocation() = default;
@ -147,7 +149,8 @@ bool FileLocation::Equals(const FileLocation& aFile) const {
nsresult FileLocation::GetData(Data& aData) { nsresult FileLocation::GetData(Data& aData) {
if (!IsZip()) { if (!IsZip()) {
return mBaseFile->OpenNSPRFileDesc(PR_RDONLY, 0444, &aData.mFd.rwget()); return mBaseFile->OpenNSPRFileDesc(PR_RDONLY, 0444,
getter_Transfers(aData.mFd));
} }
aData.mZip = mBaseZip; aData.mZip = mBaseZip;
if (!aData.mZip) { if (!aData.mZip) {
@ -166,7 +169,7 @@ nsresult FileLocation::GetData(Data& aData) {
nsresult FileLocation::Data::GetSize(uint32_t* aResult) { nsresult FileLocation::Data::GetSize(uint32_t* aResult) {
if (mFd) { if (mFd) {
PRFileInfo64 fileInfo; PRFileInfo64 fileInfo;
if (PR_SUCCESS != PR_GetOpenFileInfo64(mFd, &fileInfo)) { if (PR_SUCCESS != PR_GetOpenFileInfo64(mFd.get(), &fileInfo)) {
return NS_ErrorAccordingToNSPR(); return NS_ErrorAccordingToNSPR();
} }
@ -187,7 +190,7 @@ nsresult FileLocation::Data::GetSize(uint32_t* aResult) {
nsresult FileLocation::Data::Copy(char* aBuf, uint32_t aLen) { nsresult FileLocation::Data::Copy(char* aBuf, uint32_t aLen) {
if (mFd) { if (mFd) {
for (uint32_t totalRead = 0; totalRead < aLen;) { for (uint32_t totalRead = 0; totalRead < aLen;) {
int32_t read = PR_Read(mFd, aBuf + totalRead, int32_t read = PR_Read(mFd.get(), aBuf + totalRead,
XPCOM_MIN(aLen - totalRead, uint32_t(INT32_MAX))); XPCOM_MIN(aLen - totalRead, uint32_t(INT32_MAX)));
if (read < 0) { if (read < 0) {
return NS_ErrorAccordingToNSPR(); return NS_ErrorAccordingToNSPR();

View file

@ -17,7 +17,7 @@
#include "prio.h" #include "prio.h"
#include "prlink.h" #include "prlink.h"
#include "mozilla/Scoped.h" #include <memory> // unique_ptr
#include "nsIFile.h" #include "nsIFile.h"
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
@ -32,51 +32,26 @@ typedef int filedesc_t;
typedef const char* pathstr_t; typedef const char* pathstr_t;
#endif #endif
/**
* ScopedCloseFD is a RAII wrapper for POSIX file descriptors
*
* Instances |close()| their fds when they go out of scope.
*/
struct ScopedCloseFDTraits {
typedef int type;
static type empty() { return -1; }
static void release(type aFd) {
if (aFd != -1) {
close(aFd);
}
}
};
typedef Scoped<ScopedCloseFDTraits> ScopedClose;
#if defined(MOZILLA_INTERNAL_API) #if defined(MOZILLA_INTERNAL_API)
/** struct PRCloseDeleter {
* AutoFDClose is a RAII wrapper for PRFileDesc. void operator()(PRFileDesc* aFd) {
*
* Instances |PR_Close| their fds when they go out of scope.
**/
struct ScopedClosePRFDTraits {
typedef PRFileDesc* type;
static type empty() { return nullptr; }
static void release(type aFd) {
if (aFd) { if (aFd) {
PR_Close(aFd); PR_Close(aFd);
} }
} }
}; };
typedef Scoped<ScopedClosePRFDTraits> AutoFDClose; using AutoFDClose = UniquePtr<PRFileDesc, PRCloseDeleter>;
/* RAII wrapper for FILE descriptors */ /* RAII wrapper for FILE descriptors */
struct ScopedCloseFileTraits { struct FCloseDeleter {
typedef FILE* type; void operator()(FILE* p) {
static type empty() { return nullptr; } if (p) {
static void release(type aFile) { fclose(p);
if (aFile) {
fclose(aFile);
} }
} }
}; };
typedef Scoped<ScopedCloseFileTraits> ScopedCloseFile; using ScopedCloseFile = UniquePtr<FILE, FCloseDeleter>;
/** /**
* Fallocate efficiently and continuously allocates files via fallocate-type * Fallocate efficiently and continuously allocates files via fallocate-type

View file

@ -11,6 +11,7 @@
#include <stdio.h> #include <stdio.h>
#include "mozilla/FileUtils.h" #include "mozilla/FileUtils.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/Try.h" #include "mozilla/Try.h"
#include "mozilla/UniquePtr.h" #include "mozilla/UniquePtr.h"
#include "mozilla/UniquePtrExtensions.h" #include "mozilla/UniquePtrExtensions.h"
@ -166,18 +167,6 @@ inline FILE* TS_tfopen(const char* aPath, const char* aMode) {
} }
#endif #endif
/* RAII wrapper for FILE descriptors */
struct ScopedCloseFileTraits {
typedef FILE* type;
static type empty() { return nullptr; }
static void release(type aFile) {
if (aFile) {
fclose(aFile);
}
}
};
typedef Scoped<ScopedCloseFileTraits> ScopedCloseFile;
#if !defined(MOZ_LINKER) && !defined(__ANDROID__) #if !defined(MOZ_LINKER) && !defined(__ANDROID__)
static void XPCOMGlueUnload() { static void XPCOMGlueUnload() {
while (sTop) { while (sTop) {
@ -275,8 +264,12 @@ static XPCOMGlueLoadResult XPCOMGlueLoad(
strcat(xpcomDir, ".gtest"); strcat(xpcomDir, ".gtest");
} }
ScopedCloseFile flist; const auto flist = TS_tfopen(xpcomDir, READ_TEXTMODE);
flist = TS_tfopen(xpcomDir, READ_TEXTMODE); const auto cleanup = MakeScopeExit([&]() {
if (flist) {
fclose(flist);
}
});
if (!flist) { if (!flist) {
return Err(AsVariant(NS_ERROR_FAILURE)); return Err(AsVariant(NS_ERROR_FAILURE));
} }

View file

@ -11,25 +11,10 @@
#include "base/process_util.h" #include "base/process_util.h"
#include "mozilla/ProfilerLabels.h" #include "mozilla/ProfilerLabels.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/Unused.h" #include "mozilla/Unused.h"
#include "nsWindowsHelpers.h" #include "nsWindowsHelpers.h"
namespace {
// Scoped type used by HandleToFilename
struct ScopedMappedViewTraits {
typedef void* type;
static void* empty() { return nullptr; }
static void release(void* aPtr) {
if (aPtr) {
mozilla::Unused << UnmapViewOfFile(aPtr);
}
}
};
typedef mozilla::Scoped<ScopedMappedViewTraits> ScopedMappedView;
} // namespace
namespace mozilla { namespace mozilla {
bool HandleToFilename(HANDLE aHandle, const LARGE_INTEGER& aOffset, bool HandleToFilename(HANDLE aHandle, const LARGE_INTEGER& aOffset,
@ -44,11 +29,14 @@ bool HandleToFilename(HANDLE aHandle, const LARGE_INTEGER& aOffset,
if (!fileMapping) { if (!fileMapping) {
return false; return false;
} }
ScopedMappedView view(MapViewOfFile(fileMapping, FILE_MAP_READ, const auto view = MapViewOfFile(fileMapping, FILE_MAP_READ, aOffset.HighPart,
aOffset.HighPart, aOffset.LowPart, 1)); aOffset.LowPart, 1);
if (!view) { if (!view) {
return false; return false;
} }
const auto cleanup =
MakeScopeExit([&]() { mozilla::Unused << UnmapViewOfFile(view); });
nsAutoString mappedFilename; nsAutoString mappedFilename;
DWORD len = 0; DWORD len = 0;
SetLastError(ERROR_SUCCESS); SetLastError(ERROR_SUCCESS);

View file

@ -9,7 +9,6 @@
#include <windows.h> #include <windows.h>
#include "mozilla/Scoped.h"
#include "nsString.h" #include "nsString.h"
namespace mozilla { namespace mozilla {