-
Notifications
You must be signed in to change notification settings - Fork 0
flow: opt-in --body-throw-edges tier — body-level (no-try) dispose-not-called-on-throw
#95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| using System.IO; | ||
|
|
||
| namespace Own.Samples; | ||
|
|
||
| // P-016 throw tier — the OPT-IN `--body-throw-edges` firehose: body-level "any call may throw" | ||
| // dispose-not-called-on-throw, matching CodeQL's cs/dispose-not-called-on-throw on the no-try | ||
| // slice. OFF by default (it is CA2000-noisy — it flags even harmless MemoryStream dispose-on- | ||
| // throw); the oracle enables it to measure full recall without shifting the shipped low-FP | ||
| // default. The leak verdict below holds ONLY under --body-throw-edges; by default this file is | ||
| // silent. Kept in its own file so CI can run it in BOTH modes — running it against the default | ||
| // FlowLocalsSample would flood every acquire/use/dispose sample under the flag. | ||
| public class BodyThrowEdgesSample | ||
| { | ||
| // acquire; a may-throw call; dispose — no try. Under --body-throw-edges the WriteByte call is | ||
| // a throw point that skips the Dispose, so `mtbd` leaks on that exceptional path -> OWN001 | ||
| // "may not be disposed on every path". Default (flag off): SILENT — a body-level call is not | ||
| // treated as a leak point (the shipped posture stays below CA2000). | ||
| public void MayThrowLeaks() | ||
| { | ||
| var mtbd = new MemoryStream(); | ||
| mtbd.WriteByte(1); | ||
| mtbd.Dispose(); | ||
| } | ||
|
|
||
| // control: NOTHING between acquire and dispose can throw (adjacent), so even under the flag | ||
| // there is no throw point to skip the Dispose -> SILENT in both modes. Proves the edge needs | ||
| // an intervening may-throw statement — the flag is not "flag any undisposed-looking local". | ||
| public void AdjacentDisposeClean() | ||
| { | ||
| var adc = new MemoryStream(); | ||
| adc.Dispose(); | ||
| } | ||
|
|
||
| // Codex P2 (may-throw tier): a may-throw call lexically inside a `finally` must NOT get a | ||
| // synthetic bare exit even under the flag — a real exception there runs the ENCLOSING cleanup. | ||
| // `mtf` is disposed by the OUTER finally; the inner finally's `mtf.WriteByte(1)` may throw, but | ||
| // that throw runs the outer `mtf.Dispose()`, so `mtf` is released on every path. Without the | ||
| // IsInsideFinally guard on the may-throw path, the bare exit would skip that outer release and | ||
| // falsely flag `mtf` -> it must stay SILENT in BOTH modes (mirrors FlowLocalsSample's tif). | ||
| public void MayThrowInFinallyClean() | ||
| { | ||
| var mtf = new MemoryStream(); | ||
| try | ||
| { | ||
| try { } | ||
| finally { mtf.WriteByte(1); } | ||
| } | ||
| finally { mtf.Dispose(); } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.