Repository navigation
Commit f545f3d
committed
fix(extractor): SemaphoreSlim FIELD is dispose-optional unless AvailableWaitHandle is read (mined Npgsql)
The sound, scoped version of the SemaphoreSlim FP (per review on #91 + the user's
choice). SemaphoreSlim.Dispose() only frees a LAZILY-allocated wait handle —
allocated solely when AvailableWaitHandle is read — so a SemaphoreSlim field used
purely for Wait/WaitAsync/Release leaks nothing and is dispose-optional. Mined:
NpgsqlDataSource._setupMappingsSemaphore.
Two guards keep it sound, both flagged by reviewers on the earlier attempt:
- FIELD-scoped: the exemption lives in the field-disposable detector, NOT in the
shared IsDisposeOptional — so the flow-locals detector and the deliberate
method-bounded `semLeak` control (a prior ShareX decision: SemaphoreSlim stays
tracked for locals) are left untouched (CodeRabbit).
- AvailableWaitHandle-GATED: if `.AvailableWaitHandle` is read on the field, the
wait handle exists and Dispose must release it, so the field STAYS tracked
(Codex). The gate keys on a this/bare-receiver `.AvailableWaitHandle` access.
Regression sample SemaphoreFieldSample.cs: OptionalSemaphore._optionalSem (Wait/
Release only) is SILENT; controls still warn — WaitHandleSemaphore._handleSem
(reads AvailableWaitHandle) and HoldsCtsField._ctsControl (a non-SemaphoreSlim
CTS). The existing FlowLocalsSample.semLeak local control is unaffected (separate
detector path), asserted in the --flow-locals step.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rg8kSk1YT14x7A1vo5zgED1 parent f9605da commit f545f3d
3 files changed
Lines changed: 82 additions & 0 deletions
File tree
- .github/workflows
- frontend/roslyn
- OwnSharp.Extractor
- samples
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
| |||
261 | 262 | | |
262 | 263 | | |
263 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
264 | 280 | | |
265 | 281 | | |
266 | 282 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2296 | 2296 | | |
2297 | 2297 | | |
2298 | 2298 | | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
2299 | 2312 | | |
2300 | 2313 | | |
2301 | 2314 | | |
| |||
2323 | 2336 | | |
2324 | 2337 | | |
2325 | 2338 | | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
2326 | 2346 | | |
2327 | 2347 | | |
2328 | 2348 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
0 commit comments