diff options
| author | Chris Lattner <sabre@nondot.org> | 2008-04-01 03:49:38 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2008-04-01 03:49:38 +0000 | 
| commit | 64959dcf036033c5498ac12bca7a628bc60eee7d (patch) | |
| tree | 904bb834bf8afccfd4c14e32f47f9a8a4b17bf53 /llvm | |
| parent | bcfa564759423f40be305124bb6ad88b531f69ae (diff) | |
| download | bcm5719-llvm-64959dcf036033c5498ac12bca7a628bc60eee7d.tar.gz bcm5719-llvm-64959dcf036033c5498ac12bca7a628bc60eee7d.zip  | |
Make MappedFile::map return a const correct pointer, don't leak address space on Unix platforms.
llvm-svn: 49026
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/System/MappedFile.h | 6 | ||||
| -rw-r--r-- | llvm/lib/System/Unix/MappedFile.inc | 3 | ||||
| -rw-r--r-- | llvm/lib/System/Win32/MappedFile.inc | 2 | 
3 files changed, 5 insertions, 6 deletions
diff --git a/llvm/include/llvm/System/MappedFile.h b/llvm/include/llvm/System/MappedFile.h index c46491ee7da..127c04f002d 100644 --- a/llvm/include/llvm/System/MappedFile.h +++ b/llvm/include/llvm/System/MappedFile.h @@ -65,15 +65,13 @@ namespace sys {        return initialize(ErrMsg);      } -    /// unmap - Remove the mapped file from memory. If the file was mapped for -    /// write access, the memory contents will be automatically synchronized -    /// with the file's disk contents. +    /// unmap - Remove the mapped file from memory.      void unmap();      /// map - Reserve space for the file, map it into memory, and return a      /// pointer to it.  This returns the base memory address of the mapped file      /// or 0 if an error occurred. -    void *map(std::string* ErrMsg = 0); +    const void *map(std::string* ErrMsg = 0);      void close() { if (MapInfo) terminate(); } diff --git a/llvm/lib/System/Unix/MappedFile.inc b/llvm/lib/System/Unix/MappedFile.inc index 92dc6660439..35efaa6fcb9 100644 --- a/llvm/lib/System/Unix/MappedFile.inc +++ b/llvm/lib/System/Unix/MappedFile.inc @@ -56,6 +56,7 @@ bool MappedFile::initialize(std::string* ErrMsg) {  }  void MappedFile::terminate() { +  unmap();    assert(MapInfo && "MappedFile not initialized");    ::close(MapInfo->FD);    delete MapInfo; @@ -70,7 +71,7 @@ void MappedFile::unmap() {    BasePtr = 0;  // Mark this as non-mapped.  } -void* MappedFile::map(std::string* ErrMsg) { +const void* MappedFile::map(std::string* ErrMsg) {    assert(MapInfo && "MappedFile not initialized");    if (isMapped()) return BasePtr; diff --git a/llvm/lib/System/Win32/MappedFile.inc b/llvm/lib/System/Win32/MappedFile.inc index 830905debca..4f30f56f74c 100644 --- a/llvm/lib/System/Win32/MappedFile.inc +++ b/llvm/lib/System/Win32/MappedFile.inc @@ -75,7 +75,7 @@ void MappedFile::unmap() {    }  } -void* MappedFile::map(std::string* ErrMsg) { +const void* MappedFile::map(std::string* ErrMsg) {    if (!isMapped()) {      MapInfo->hMapping = CreateFileMapping(MapInfo->hFile, NULL, PAGE_READONLY,                                            0, 0, NULL);  | 

