[compiler-rt] r233373 - tsan: don't write to meta shadow unnecessarily

Dmitry Vyukov dvyukov at google.com
Fri Mar 27 05:22:45 PDT 2015


Author: dvyukov
Date: Fri Mar 27 07:22:44 2015
New Revision: 233373

URL: http://llvm.org/viewvc/llvm-project?rev=233373&view=rev
Log:
tsan: don't write to meta shadow unnecessarily

If user does malloc(1<<30), the write to meta shadow
can cause excessive memory consumption.


Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_sync.cc

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_sync.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_sync.cc?rev=233373&r1=233372&r2=233373&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_sync.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_sync.cc Fri Mar 27 07:22:44 2015
@@ -88,11 +88,13 @@ bool MetaMap::FreeRange(ThreadState *thr
     end++;
   for (; meta < end; meta++) {
     u32 idx = *meta;
+    if (idx == 0) {
+      // Note: don't write to meta in this case -- the block can be huge.
+      continue;
+    }
     *meta = 0;
-    for (;;) {
-      if (idx == 0)
-        break;
-      has_something = true;
+    has_something = true;
+    while (idx != 0) {
       if (idx & kFlagBlock) {
         block_alloc_.Free(&thr->block_cache, idx & ~kFlagMask);
         break;





More information about the llvm-commits mailing list