|
| 1 | +# A parameter guard spelled as an early return defeats the #278 guard detector (soundness FN) |
| 2 | + |
| 3 | +**Pattern.** The exact SectorTS `UnregOnlyGoodys` guard from |
| 4 | +`subscription-param-guarded-unregister`, rewritten from the enclosing-branch |
| 5 | +form into the early-return form: |
| 6 | + |
| 7 | +```csharp |
| 8 | +// demoted today (enclosing branch): // credited today (early return): |
| 9 | +void Cleanup(bool keepAlive) void Cleanup(bool keepAlive) |
| 10 | +{ { |
| 11 | + if (!keepAlive) if (keepAlive) |
| 12 | + { return; |
| 13 | + source.Changed -= OnChanged; source.Changed -= OnChanged; |
| 14 | + } } |
| 15 | +} |
| 16 | +``` |
| 17 | + |
| 18 | +The two spellings are semantically identical — the caller chooses whether the |
| 19 | +`-=` runs — but only the left one is demoted. |
| 20 | + |
| 21 | +**The bug (Own.NET extractor).** `IsParamGuardedRelease` |
| 22 | +(`frontend/roslyn/OwnSharp.Extractor/Program.cs`, #278 rule 2) walks the |
| 23 | +**lexical ancestors** of the `-=` site and demotes when an enclosing |
| 24 | +`if`/`?:`/`switch`/`while`/`for` condition references a parameter. An early |
| 25 | +`return` guard is a preceding **sibling** statement, never an ancestor, so it |
| 26 | +is invisible. Meanwhile the symbol-based teardown closure |
| 27 | +(`TeardownContextMethods`) adds `Cleanup` because `Dispose()` calls it — |
| 28 | +argument **values** are not consulted, so `Cleanup(keepAlive: true)` credits |
| 29 | +the helper even though that call provably skips the release. Net: `before.cs` |
| 30 | +is silent, and the leak class #293 closed reopens one refactoring away. |
| 31 | + |
| 32 | +**Why the core is not the gap.** The `.own` reduction models the guard as the |
| 33 | +branch it is, and the branch-sensitive core flags it (OWN001, "not released on |
| 34 | +every path"). This mirrors the Python bridge's own D7 fix |
| 35 | +(`docs/notes/interprocedural-tz.md`, INF-S3: an early `return` reachable before |
| 36 | +a forward makes the transfer conditional) — the same theorem, unfixed on the |
| 37 | +extractor side. |
| 38 | + |
| 39 | +**The fix (#305).** `IsParamGuardedByEarlyReturn`, folded into |
| 40 | +`IsParamGuardedRelease`: a `return` lexically preceding the site inside the |
| 41 | +enclosing callable, guarded by a parameter-referencing condition, demotes — |
| 42 | +EXCEPT the canonical negated-disposing early exit (`if (!disposing) return;`), |
| 43 | +which guarantees the site *does* run on every `Dispose()` call and stays |
| 44 | +credited. Timer twin: `timer-stop-early-return-guard` (shared predicate). See |
| 45 | +`docs/notes/teardown-predicate-adversarial-audit.md` (attack A). |
| 46 | + |
| 47 | +**CI impact.** `before.cs` flips to caught with the fix; `after.cs` reuses the |
| 48 | +proven-silent helper-from-Dispose shape of |
| 49 | +`subscription-overload-conflated-cleanup`. |
0 commit comments