[compiler-rt] r192716 - [lsan] Fix bug when discovering indirectly leaked objects.
Sergey Matveev
earthdok at google.com
Tue Oct 15 09:00:12 PDT 2013
Author: smatveev
Date: Tue Oct 15 11:00:11 2013
New Revision: 192716
URL: http://llvm.org/viewvc/llvm-project?rev=192716&view=rev
Log:
[lsan] Fix bug when discovering indirectly leaked objects.
If an object contains pointers to itself, that doesn't make it indirectly
leaked. D'oh!
Added:
compiler-rt/trunk/lib/lsan/lit_tests/TestCases/pointer_to_self.cc
Modified:
compiler-rt/trunk/lib/lsan/lsan_common.cc
Added: compiler-rt/trunk/lib/lsan/lit_tests/TestCases/pointer_to_self.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lit_tests/TestCases/pointer_to_self.cc?rev=192716&view=auto
==============================================================================
--- compiler-rt/trunk/lib/lsan/lit_tests/TestCases/pointer_to_self.cc (added)
+++ compiler-rt/trunk/lib/lsan/lit_tests/TestCases/pointer_to_self.cc Tue Oct 15 11:00:11 2013
@@ -0,0 +1,18 @@
+// Regression test: pointers to self should not confuse LSan into thinking the
+// object is indirectly leaked. Only external pointers count.
+// RUN: LSAN_BASE="report_objects=1:use_registers=0"
+// RUN: %clangxx_lsan %s -o %t
+// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main() {
+ void *p = malloc(1337);
+ *reinterpret_cast<void **>(p) = p;
+ fprintf(stderr, "Test alloc: %p.\n", p);
+}
+// CHECK: Test alloc: [[ADDR:.*]].
+// CHECK: Directly leaked 1337 byte object at [[ADDR]]
+// CHECK: LeakSanitizer: detected memory leaks
+// CHECK: SUMMARY: LeakSanitizer:
Modified: compiler-rt/trunk/lib/lsan/lsan_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.cc?rev=192716&r1=192715&r2=192716&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.cc Tue Oct 15 11:00:11 2013
@@ -138,6 +138,8 @@ void ScanRangeForPointers(uptr begin, up
if (!CanBeAHeapPointer(reinterpret_cast<uptr>(p))) continue;
uptr chunk = PointsIntoChunk(p);
if (!chunk) continue;
+ // Pointers to self don't count. This matters when tag == kIndirectlyLeaked.
+ if (chunk == begin) continue;
LsanMetadata m(chunk);
// Reachable beats ignored beats leaked.
if (m.tag() == kReachable) continue;
More information about the llvm-commits
mailing list