[PATCH] [ASan] Don't crash in DescribeHeapAddress if we don't know the current thread's ID

Timur Iskhodzhanov timurrrr at google.com
Tue Sep 10 01:18:53 PDT 2013


  Make ~ScopedInErrorReport() even simpler

Hi kcc,

http://llvm-reviews.chandlerc.com/D1635

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1635?vs=4158&id=4159#toc

Files:
  asan_report.cc

Index: asan_report.cc
===================================================================
--- asan_report.cc
+++ asan_report.cc
@@ -166,6 +166,11 @@
   }
 }
 
+static void DescribeThread(AsanThread *t) {
+  if (t)
+    DescribeThread(t->context());
+}
+
 // ---------------------- Address Descriptions ------------------- {{{1
 
 static bool IsASCII(unsigned char c) {
@@ -377,7 +382,7 @@
   Printf("HINT: this may be a false positive if your program uses "
              "some custom stack unwind mechanism or swapcontext\n"
              "      (longjmp and C++ exceptions *are* supported)\n");
-  DescribeThread(t->context());
+  DescribeThread(t);
   return true;
 }
 
@@ -415,13 +420,11 @@
       GetThreadContextByTidLocked(chunk.AllocTid());
   StackTrace alloc_stack;
   chunk.GetAllocStack(&alloc_stack);
-  AsanThread *t = GetCurrentThread();
-  CHECK(t);
   char tname[128];
   Decorator d;
+  AsanThreadContext *free_thread = 0;
   if (chunk.FreeTid() != kInvalidTid) {
-    AsanThreadContext *free_thread =
-        GetThreadContextByTidLocked(chunk.FreeTid());
+    free_thread = GetThreadContextByTidLocked(chunk.FreeTid());
     Printf("%sfreed by thread T%d%s here:%s\n", d.Allocation(),
            free_thread->tid,
            ThreadNameWithParenthesis(free_thread, tname, sizeof(tname)),
@@ -433,19 +436,17 @@
            d.Allocation(), alloc_thread->tid,
            ThreadNameWithParenthesis(alloc_thread, tname, sizeof(tname)),
            d.EndAllocation());
-    PrintStack(&alloc_stack);
-    DescribeThread(t->context());
-    DescribeThread(free_thread);
-    DescribeThread(alloc_thread);
   } else {
     Printf("%sallocated by thread T%d%s here:%s\n", d.Allocation(),
            alloc_thread->tid,
            ThreadNameWithParenthesis(alloc_thread, tname, sizeof(tname)),
            d.EndAllocation());
-    PrintStack(&alloc_stack);
-    DescribeThread(t->context());
-    DescribeThread(alloc_thread);
   }
+  PrintStack(&alloc_stack);
+  DescribeThread(GetCurrentThread());
+  if (free_thread)
+    DescribeThread(free_thread);
+  DescribeThread(alloc_thread);
 }
 
 void DescribeAddress(uptr addr, uptr access_size) {
@@ -535,10 +536,7 @@
   // Destructor is NORETURN, as functions that report errors are.
   NORETURN ~ScopedInErrorReport() {
     // Make sure the current thread is announced.
-    AsanThread *curr_thread = GetCurrentThread();
-    if (curr_thread) {
-      DescribeThread(curr_thread->context());
-    }
+    DescribeThread(GetCurrentThread());
     // Print memory stats.
     if (flags()->print_stats)
       __asan_print_accumulated_stats();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1635.2.patch
Type: text/x-patch
Size: 2604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130910/d0994813/attachment.bin>


More information about the llvm-commits mailing list