Files
clang-p2996/compiler-rt/test/lsan/TestCases/Darwin/dispatch_continuations.mm
Leonard Grey ed2c3f46f5 [lsan][Darwin] Scan libdispatch and Foundation memory regions
libdispatch uses its own heap (_dispatch_main_heap) for some allocations, including the dispatch_continuation_t that holds a dispatch source's event handler.
Objective-C block trampolines (creating methods at runtime with a block as the implementations) use the VM_MEMORY_FOUNDATION region (see 8701d5672d/runtime/objc-block-trampolines.mm (L371)).

This change scans both regions to fix false positives. See tests for details; unfortunately I was unable to reduce the trampoline example with imp_implementationWithBlock on a new class, so I'm resorting to something close to the bug as seen in the wild.

Differential Revision: https://reviews.llvm.org/D129385
2022-09-14 16:46:40 -04:00

25 lines
870 B
Plaintext

// Test that dispatch continuation memory region is scanned.
// RUN: %clangxx_lsan %s -o %t -framework Foundation
// RUN: %env_lsan_opts="report_objects=1" %run %t 2>&1 && echo "" | FileCheck %s
#include <dispatch/dispatch.h>
#include <sanitizer/lsan_interface.h>
int main() {
// Reduced from `CFRunLoopCreate`
dispatch_queue_t fake_rl_queue = dispatch_get_global_queue(2, 0);
dispatch_source_t timer =
dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, fake_rl_queue);
dispatch_source_set_event_handler(timer, ^{
});
dispatch_source_set_timer(timer, DISPATCH_TIME_FOREVER, DISPATCH_TIME_FOREVER,
321);
dispatch_resume(timer);
__lsan_do_leak_check();
dispatch_source_cancel(timer);
dispatch_release(timer);
return 0;
}
// CHECK-NOT: LeakSanitizer: detected memory leaks