diff options
author | djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-12-09 21:19:38 +0000 |
---|---|---|
committer | djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-12-09 21:19:38 +0000 |
commit | 59204b4813bfbf50189b256a29cdfae85a77bca1 (patch) | |
tree | 091e7c3f8fae38e4498336c533d1f82e05fe9aef /src/core | |
parent | e9f091d7cd6eeccb0c1b84226a8543dc8a3d285a (diff) |
Closing fd for mmap after mapping succeeds.
Review URL: http://codereview.appspot.com/5467058
git-svn-id: http://skia.googlecode.com/svn/trunk@2847 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkMMapStream.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/core/SkMMapStream.cpp b/src/core/SkMMapStream.cpp index 005c8e5cee..0aec5e19d2 100644 --- a/src/core/SkMMapStream.cpp +++ b/src/core/SkMMapStream.cpp @@ -14,7 +14,7 @@ SkMMAPStream::SkMMAPStream(const char filename[]) { - fFildes = -1; // initialize to failure case + fAddr = NULL; // initialize to failure case int fildes = open(filename, O_RDONLY); if (fildes < 0) @@ -36,16 +36,21 @@ SkMMAPStream::SkMMAPStream(const char filename[]) size_t size = static_cast<size_t>(offset); void* addr = mmap(NULL, size, PROT_READ, MAP_SHARED, fildes, 0); + + // According to the POSIX documentation of mmap it adds an extra reference + // to the file associated with the fildes which is not removed by a + // subsequent close() on that fildes. This reference is removed when there + // are no more mappings to the file. + close(fildes); + if (MAP_FAILED == addr) { SkDEBUGF(("---- failed to mmap(%s) for mmap stream error=%d\n", filename, errno)); - close(fildes); return; } this->INHERITED::setMemory(addr, size); - fFildes = fildes; fAddr = addr; fSize = size; } @@ -63,11 +68,10 @@ void SkMMAPStream::setMemory(const void* data, size_t length, bool copyData) void SkMMAPStream::closeMMap() { - if (fFildes >= 0) + if (fAddr) { munmap(fAddr, fSize); - close(fFildes); - fFildes = -1; + fAddr = NULL; } } |