Index: base/memory/discardable_memory_allocator_android.cc |
diff --git a/base/memory/discardable_memory_allocator_android.cc b/base/memory/discardable_memory_allocator_android.cc |
index 97e9abd7d6eec8baa54e2d58bed24fd6d1b2c3ba..1588317ef646b30a1e1a7f825e5414bb1a645886 100644 |
--- a/base/memory/discardable_memory_allocator_android.cc |
+++ b/base/memory/discardable_memory_allocator_android.cc |
@@ -16,6 +16,7 @@ |
#include "base/basictypes.h" |
#include "base/containers/hash_tables.h" |
#include "base/file_util.h" |
+#include "base/files/scoped_file.h" |
#include "base/logging.h" |
#include "base/memory/discardable_memory.h" |
#include "base/memory/scoped_vector.h" |
@@ -65,14 +66,13 @@ bool CreateAshmemRegion(const char* name, |
size_t size, |
int* out_fd, |
void** out_address) { |
- int fd = ashmem_create_region(name, size); |
- if (fd < 0) { |
+ base::ScopedFD fd(ashmem_create_region(name, size)); |
+ if (!fd.is_valid()) { |
DLOG(ERROR) << "ashmem_create_region() failed"; |
return false; |
} |
- file_util::ScopedFD fd_closer(&fd); |
- const int err = ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE); |
+ const int err = ashmem_set_prot_region(fd.get(), PROT_READ | PROT_WRITE); |
if (err < 0) { |
DLOG(ERROR) << "Error " << err << " when setting protection of ashmem"; |
return false; |
@@ -82,14 +82,13 @@ bool CreateAshmemRegion(const char* name, |
// Lock() and Unlock(), data could get lost if they are not written to the |
// underlying file when Unlock() gets called. |
void* const address = mmap( |
- NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
+ NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd.get(), 0); |
if (address == MAP_FAILED) { |
DPLOG(ERROR) << "Failed to map memory."; |
return false; |
} |
- ignore_result(fd_closer.release()); |
- *out_fd = fd; |
+ *out_fd = fd.release(); |
*out_address = address; |
return true; |
} |