← Back to Pull requests

free open file handles when an archive is discarded and release compression streams in deallocate #605

Open
unknown opened this pull request with 224 lines diff across 2 files
View on GitHub
unknown unknown commented on Oct 04, 2026 01:26 UTC
Author

Problem

A zip_file_t handle 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_fclose removes it again,
* zip_discard frees any handle still open before tearing down sources.

The compression wrappers release their underlying stream in deallocate now as well, which is safe to call twice with end, 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_leak runs 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.

Diff: 224 lines (+168 / -56) across 2 files Reviewer: copilot-pull-request-reviewer[bot] Review duration: 4m
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
0.37
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 77% · Reviewer familiarity: 35%
37%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Assignees
Unassigned
Labels
risk: low confidence: 37.2% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 36.9% (MEDIUM) · Higher = larger blast radius
36.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 37.2% · Lower = rushed or shallow review
37.2%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 23.1% · Safe to merge
23.1%
Repository