diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-14 19:36:50 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-14 19:36:50 +0000 |
commit | c0e895e2961bd05570b0d7660016914601bf8c7d (patch) | |
tree | 3104b59d5f4d22ad60a35a3bcefdb7caff27d3c0 /base/file_util_posix.cc | |
parent | 5fcc99e7cf20aa9d0c44e2fdaef207d9e45f907a (diff) | |
download | chromium_src-c0e895e2961bd05570b0d7660016914601bf8c7d.zip chromium_src-c0e895e2961bd05570b0d7660016914601bf8c7d.tar.gz chromium_src-c0e895e2961bd05570b0d7660016914601bf8c7d.tar.bz2 |
Implement ScopedFD in terms of ScopedGeneric.
Move to a new file base/files/scoped_file.h. I will also add ScopedFILE to here (currently in file_util.h) later.
I think there is a crash in the old code in content/browser/zygote_host/zygote_host_impl_linux.cc that this patch should fix. The old ScopedFD took the address of something in a vector that is being modified.
I removed SafeScopedFD from content/common/sandbox_linux/sandbox_linux.cc since base's ScopedFD not CHECKs on close failure (this is a more recent addition).
BUG=
R=agl@chromium.org, viettrungluu@chromium.org
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=257001
Review URL: https://codereview.chromium.org/191673003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257179 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r-- | base/file_util_posix.cc | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index 7e7dc05..fb4ebcf 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -33,6 +33,7 @@ #include "base/basictypes.h" #include "base/files/file_enumerator.h" #include "base/files/file_path.h" +#include "base/files/scoped_file.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" @@ -172,15 +173,15 @@ int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) { bool DetermineDevShmExecutable() { bool result = false; FilePath path; - int fd = CreateAndOpenFdForTemporaryFile(FilePath("/dev/shm"), &path); - if (fd >= 0) { - file_util::ScopedFD shm_fd_closer(&fd); + + ScopedFD fd(CreateAndOpenFdForTemporaryFile(FilePath("/dev/shm"), &path)); + if (fd.is_valid()) { DeleteFile(path, false); long sysconf_result = sysconf(_SC_PAGESIZE); CHECK_GE(sysconf_result, 0); size_t pagesize = static_cast<size_t>(sysconf_result); CHECK_GE(sizeof(pagesize), sizeof(sysconf_result)); - void *mapping = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0); + void *mapping = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd.get(), 0); if (mapping != MAP_FAILED) { if (mprotect(mapping, pagesize, PROT_READ | PROT_EXEC) == 0) result = true; @@ -660,11 +661,10 @@ bool GetFileInfo(const FilePath& file_path, File::Info* results) { stat_wrapper_t file_info; #if defined(OS_ANDROID) if (file_path.IsContentUri()) { - int fd = OpenContentUriForRead(file_path); - if (fd < 0) + ScopedFD fd(OpenContentUriForRead(file_path)); + if (!fd.is_valid()) return false; - file_util::ScopedFD scoped_fd(&fd); - if (CallFstat(fd, &file_info) != 0) + if (CallFstat(fd.get(), &file_info) != 0) return false; } else { #endif // defined(OS_ANDROID) |