fix: release GET KEY expression temporaries

This commit is contained in:
Hermes Agent
2026-09-26 04:09:02 +00:00
parent e4ded3acc7
commit 970a446f4e
4 changed files with 58 additions and 1 deletions
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
"""Regression check for GET KEY expression temporaries."""
from pathlib import Path
import os
import subprocess
import tempfile
ROOT = Path(__file__).resolve().parent.parent
def main() -> int:
if os.name == "nt":
print("SKIP: LeakSanitizer check is POSIX-only")
return 0
with tempfile.TemporaryDirectory(prefix="claro-get-key-cleanup-") as tmp:
tmp_path = Path(tmp)
binary = tmp_path / "claro-lsan"
script = tmp_path / "get_key_expressions.claro"
script.write_text(
'SET items TO MAP\nPUT items KEY "selected" VALUE "value"\n'
+ 'GET items KEY "selected" AS selected\n' * 2000
+ "SAY selected\n",
encoding="utf-8",
)
build = subprocess.run(
["gcc", "-std=c99", "-O0", "-g", "-fsanitize=address,undefined",
"src/claro.c", "-o", str(binary), "-lm"],
cwd=ROOT, text=True, capture_output=True,
)
if build.returncode:
print(build.stdout, end="")
print(build.stderr, end="")
return build.returncode
run = subprocess.run(
[str(binary), str(script)], cwd=ROOT, text=True, capture_output=True,
env={**os.environ, "ASAN_OPTIONS": "detect_leaks=1"},
)
if run.returncode or "LeakSanitizer" in run.stderr or "SUMMARY:" in run.stderr:
print("FAIL: GET KEY expression values still leak")
print(run.stdout, end="")
print(run.stderr, end="")
return 1
if run.stdout != "value\n":
print(f"FAIL: unexpected GET KEY probe output: {run.stdout!r}")
return 1
print("PASS: GET KEY expression values are released")
return 0
if __name__ == "__main__":
raise SystemExit(main())