Remove Max Leaks Limit Leak Sanitizer

I am interested in removing the limit on the maximum number of leak considered by Leak Sanitizer. This limit is artificially imposed in compiler-rt/lib/lsan/lsan_common.cpp with the following variable:

// A hard limit on the number of distinct leaks, to avoid quadratic complexity
// in LeakReport::AddLeakedChunk(). We don't expect to ever see this many leaks
// in real-world applications.
// FIXME: Get rid of this limit by moving logic into DedupLeaks.
const uptr kMaxLeaksConsidered = 5000;

Is anyone familiar with this constraint or where DedupLeaks is (I couldn’t find it)? @vitalybuka it looks like you touched this code in this commit [lsan] Reduce StopTheWorld access to StackDepot · llvm/llvm-project@f72e509 · GitHub. Do you have any thoughts/advice on removing the constraint?

There is N^2 loops in LeakReport::AddLeakedChunks
We can remove the constant if we remove N^2 there

We can sort/dedup at the end of LeakReport::AddLeakedChunks
Or we can use DenseMap<> instead of nested loop of AddLeakedChunks

1 Like