Skip to content

Commit

Permalink
compiler-rt: do not check leak when certain number of reports
Browse files Browse the repository at this point in the history
While running deepsjeng_r, PLSan generates too many false reports
and we are still investigating it. Because generating leak reports
is very inefficient, do not even check after certain threshold.
  • Loading branch information
hygoni committed Jun 30, 2024
1 parent ba04e9e commit fd5e8a5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions compiler-rt/lib/plsan/plsan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include "sanitizer_common/sanitizer_stacktrace.h"
#include "sanitizer_common/sanitizer_symbolizer.h"

#define PLSAN_REPORT_COUNT_THRESHOLD 100
// this counter is intentionally not atomic
// because it doesn't needs to be precise.
// for performance, use it in a relaxed way.
int report_count = 0;

struct LazyCheckInfo {
__sanitizer::Vector<void *> *RefCountZeroAddrs;
};
Expand Down Expand Up @@ -82,6 +88,9 @@ extern "C" void __plsan_free_local_variable(void **addr, uptr size,
}

extern "C" void __plsan_lazy_check(void *ret_addr) {
if (report_count > PLSAN_REPORT_COUNT_THRESHOLD)
return;

__sanitizer::Vector<void *> *lazy_check_addr_list =
__plsan::local_var_ref_count_zero_list;

Expand All @@ -90,6 +99,7 @@ extern "C" void __plsan_lazy_check(void *ret_addr) {
__plsan::Metadata *metadata =
__plsan::GetMetadata((*lazy_check_addr_list)[i]);
__lsan::setLeakedLoc(metadata->GetAllocTraceId());
report_count++;
lazy_check_addr_list->PopBack();
}
}
Expand Down Expand Up @@ -175,8 +185,12 @@ void check_returned_or_stored_value(void *ret_ptr_addr,
}

void check_memory_leak(Metadata *metadata) {
if (report_count > PLSAN_REPORT_COUNT_THRESHOLD)
return;

if (metadata && GetRefCount(metadata) == 0) {
__lsan::setLeakedLoc(metadata->GetAllocTraceId());
report_count++;
}
}

Expand Down

0 comments on commit fd5e8a5

Please sign in to comment.