Fix LSAN workflow when run outside of PR. (#5568)

This commit is contained in:
Rot127 2025-12-04 16:28:10 +00:00 committed by GitHub
parent 22099333e6
commit 2fa0c2c96f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View file

@ -115,11 +115,10 @@ jobs:
cflags: "-DASAN=1 -DRZ_ASSERT_STDOUT=1 -ftrivial-auto-var-init=pattern -funsigned-char"
meson_options: -Dbuildtype=debug -Db_sanitize=leak --werror
asan: true
enable: ${{ github.event_name == 'pull_request' }}
lsan_options: log_path=/tmp/lsan_logs/log
continue-on-error: false
run_tests: true
enabled: ${{ needs.changes.outputs.edited == 'true' }}
enabled: ${{ (needs.changes.outputs.edited == 'true' || github.event_name == 'pull_request') }}
timeout: 120
# The existing leaks in Rizin will make the tests fail otherwise
# before it runs the script to check for new leaks.
@ -363,7 +362,7 @@ jobs:
LSAN_OPTIONS: ${{ matrix.lsan_options }}
CC: ${{ matrix.compiler }}
- name: Check for new leaks
if: matrix.lsan_options != ''
if: matrix.lsan_options != '' && matrix.enabled
run: |
./sys/lsan_check.py ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} /tmp/lsan_logs/*
- name: Generate coverage data

View file

@ -18,6 +18,14 @@ def get_changed_lines(
"""
changed: Dict[Path, List[Tuple[int, int]]] = {}
try:
subprocess.check_call(["git", "rev-parse", "--verify", f"{base_ref}"])
subprocess.check_call(["git", "rev-parse", "--verify", f"{head_ref}"])
except subprocess.CalledProcessError:
# References were malformed.
print(f"One or both references are invalid: {base_ref} and {head_ref}")
sys.exit(1)
# --unified=0 gives hunks like “@@ -L,C +L,C @@” (we care about the + side)
cmd = ["git", "diff", "--unified=0", f"{base_ref}..{head_ref}"]
out = subprocess.check_output(cmd, text=True, stderr=subprocess.DEVNULL)