fix: release READ FILE expression values

This commit is contained in:
Hermes Agent
2026-10-07 23:34:49 +00:00
parent e6a1e02790
commit 7275f457ad
5 changed files with 62 additions and 1 deletions
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
"""Check that READ FILE releases its evaluated path expression."""
from pathlib import Path
import os
import subprocess
import sys
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="read-expression-cleanup-", dir=os.environ.get("TMPDIR")) as tmp:
tmp_path = Path(tmp)
source = tmp_path / "input.txt"
source.write_text("hello\n", encoding="utf-8")
script = tmp_path / "repeated_read.claro"
quoted = str(source).replace('\\', '\\\\').replace('"', '\\"')
script.write_text((f'READ FILE "{quoted}" AS contents\n' * 2000) + 'SAY contents\n', encoding="utf-8")
binary = tmp_path / "claro-asan"
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="", file=sys.stderr)
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: repeated READ FILE expressions retain allocations")
print(run.stdout, end="")
print(run.stderr, end="", file=sys.stderr)
return 1
if run.stdout != "hello\n\n":
print(f"FAIL: unexpected READ FILE output: {run.stdout!r}")
return 1
print("PASS: repeated READ FILE expressions release temporary values")
return 0
if __name__ == "__main__":
raise SystemExit(main())
+1
View File
@@ -50,6 +50,7 @@ def main():
run([sys.executable, "tools/validate_runtime_error_cleanup.py"])
run([sys.executable, "tools/validate_get_argument_expression_cleanup.py"])
run([sys.executable, "tools/validate_get_env_expression_cleanup.py"])
run([sys.executable, "tools/validate_read_file_expression_cleanup.py"])
run([sys.executable, "tools/validate_version_convention.py"])
run([str(EXE), "examples/networking.claro"])
print("v1.18.26 validation complete")