Fix a use-after-unmap bug in /proc/self/maps caching. The cached buffer was occasiona...
authorAlexander Potapenko <glider@google.com>
Tue, 4 Dec 2012 23:30:00 +0000 (23:30 +0000)
committerAlexander Potapenko <glider@google.com>
Tue, 4 Dec 2012 23:30:00 +0000 (23:30 +0000)
llvm-svn: 169335

compiler-rt/lib/sanitizer_common/sanitizer_linux.cc

index 58f0ce9..071620f 100644 (file)
@@ -236,7 +236,11 @@ MemoryMappingLayout::MemoryMappingLayout() {
 }
 
 MemoryMappingLayout::~MemoryMappingLayout() {
-  UnmapOrDie(proc_self_maps_.data, proc_self_maps_.mmaped_size);
+  // Only unmap the buffer if it is different from the cached one. Otherwise
+  // it will be unmapped when the cache is refreshed.
+  if (proc_self_maps_.data != cached_proc_self_maps_.data) {
+    UnmapOrDie(proc_self_maps_.data, proc_self_maps_.mmaped_size);
+  }
 }
 
 void MemoryMappingLayout::Reset() {