free open file handles when an archive is discarded and release compression streams in deallocate #605
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.37) × (1 − Review Confidence (0.37)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 224 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 77% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.324
Real PR Conversation Timeline
1 comments
"Review active on #605"
general
weight: 0.35
copilot-pull-request-reviewer[bot]
Problem
A
zip_file_thandle was not tracked anywhere in the archive that created it. When an application discards or closes an archive while a file is still open, the handle leaked, together with everything hanging off it: the layered source stack and the compression stream state inside it. The same applies to the compression wrappers, which released their zlib, bzip2, lzma or zstd stream only when the source went through a full open and close cycle, so any source freed while still open stranded that state as well.The regression test attached to this change demonstrates the effect: it opens a deflated entry 200 times from an archive held in memory and discards the archive each time without closing the file. Under a leak checker the current code leaks about 9.8 MB in 3000 allocations, roughly 48 KB per open file. With this change the same program leaks nothing.
Change
Open files are now tracked the same way open sources are tracked:
file creation registers the handle in the archive,
zip_fcloseremoves it again,*
zip_discardfrees any handle still open before tearing down sources.The compression wrappers release their underlying stream in
deallocatenow as well, which is safe to call twice withend, so a source freed while it is open does not strand the stream state even outside the discard path. A partially initialized zstd stream is also released when its setup fails partway.Testing
The new regression test
compress_stream_leakruns in the regular suite and passes on the full upstream matrix (Linux, macOS, Windows, BSD, Solaris). In addition I verified the leak itself under AddressSanitizer with leak detection enabled: the test leaks 9,827,200 bytes in 3000 allocations on current main and reports nothing with this change applied.