Compare commits

...

2 Commits

Author SHA1 Message Date
e7a2b53b71 Refine lsan.supp
Signed-off-by: Yuanyuan Chen <cyyever@outlook.com>
2025-11-08 09:47:01 +08:00
cyy
d35efe6899 Enable Leak Sanitizer
Signed-off-by: Yuanyuan Chen <cyyever@outlook.com>
2025-11-08 09:47:01 +08:00
3 changed files with 16 additions and 10 deletions

View File

@ -229,11 +229,13 @@ fi
# if you're not careful. Check this if you made some changes and the
# ASAN test is not working
if [[ "$BUILD_ENVIRONMENT" == *asan* ]]; then
export ASAN_OPTIONS=detect_leaks=0:symbolize=1:detect_stack_use_after_return=true:strict_init_order=true:detect_odr_violation=1:detect_container_overflow=0:check_initialization_order=true:debug=true
export ASAN_OPTIONS=detect_leaks=1:symbolize=1:detect_stack_use_after_return=true:strict_init_order=true:detect_odr_violation=1:detect_container_overflow=0:check_initialization_order=true:debug=true:fast_unwind_on_malloc=1:print_suppressions=0
if [[ "$BUILD_ENVIRONMENT" == *cuda* ]]; then
export ASAN_OPTIONS="${ASAN_OPTIONS}:protect_shadow_gap=0"
fi
export UBSAN_OPTIONS=print_stacktrace=1:suppressions=$PWD/ubsan.supp
# Suppress some hard to solve indirect leaks
export LSAN_OPTIONS="suppressions=$PWD/lsan.supp"
export PYTORCH_TEST_WITH_ASAN=1
export PYTORCH_TEST_WITH_UBSAN=1
# TODO: Figure out how to avoid hard-coding these paths

11
lsan.supp Normal file
View File

@ -0,0 +1,11 @@
leak:PyMem_RawMalloc
leak:PyObject_Malloc
leak:unicodeobject
leak:obmalloc
leak:gcmodule
leak:listobject
leak:bytesobject
leak:torch::jit::tensorexpr::TensorExprKernel::preAllocIntermediateBufs
leak:optree
leak:python
leak:torch::tensors::initialize_aten_types

View File

@ -663,14 +663,6 @@ static c10::ArrayRef<T> get_set_cached_attr(
size_t new_size = py::len(obj);
// We do the smallvector optimization here: any time the new_size is <=5,
// we always allocate our buffer to size 5, so that if the next resize
// is also to <=5 elements, we don't need to reallocate.
// Note: I tried removing this optimization and tripped ASAN
// in a batchnorm kernel here:
// https://pipelinesghubeus21.actions.githubusercontent.com/mBh68xKhi8LyM7tp3vECvYXNFvuV4gyVGgmYCteuEZP9JH92QN/_apis/pipelines/1/runs/3373307/signedlogcontent/790?urlExpires=2023-09-15T21%3A13%3A51.4327798Z&urlSigningMethod=HMACV1&urlSignature=tDeX7ZqaARVU5NNwyr5yYqqkWq3A2j4z8FFdqYwGr0Q%3D@lint-ignore
// We should fix this instead.
bool needs_resize = false;
// We need to resize if:
// (1) we haven't allocated our buffer at all yet
// (2) Our buffer size is different from the new size
@ -678,7 +670,8 @@ static c10::ArrayRef<T> get_set_cached_attr(
// is always allocated to at least size 5, and any resizes
// within the <= 5 regime to not require a reallocation).
auto is_smallvector = curr_size <= 5;
needs_resize = !is_buffer_allocated || (is_smallvector && new_size > 5) ||
bool needs_resize = !is_buffer_allocated ||
(is_smallvector && new_size > 5) ||
(!is_smallvector && curr_size != new_size);
if (needs_resize) {
// If our current buffer is not the right size (either because we haven't