|
| 1 | +# ShareX — the annotation toolbar `Form` is built but never disposed |
| 2 | + |
| 3 | +**Found by the issue #201 oracle sweep** (`docs/notes/oracle-sweep-2026-07-10.md`). |
| 4 | +Target: `ShareX/ShareX` @ `0df9ca4`, `ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs` |
| 5 | +(`CreateToolbar`, ~lines 62-1246) and `ShapeManager.cs:2406-2411` (`Dispose`). |
| 6 | + |
| 7 | +**Pattern.** `ShapeManager.CreateToolbar()` builds the on-screen annotation/region- |
| 8 | +capture toolbar as a plain `Form` (`menuForm`), hosting a `ToolStripEx` with roughly |
| 9 | +38 buttons, menu items, numeric-updowns, and combo-boxes — all created and owned |
| 10 | +by `ShapeManager` itself (verified: every one of those ~38 fields is populated in |
| 11 | +`CreateToolbar`, and `menuForm.Controls.Add(tsMain)` / `tsMain.Items.Add(...)` wires |
| 12 | +them into the same `Form`). `ShapeManager` **does** implement `IDisposable` and |
| 13 | +**does** have a real `Dispose()`: |
| 14 | + |
| 15 | +```csharp |
| 16 | +public void Dispose() |
| 17 | +{ |
| 18 | + DeleteAllShapes(); |
| 19 | + history.Dispose(); |
| 20 | +} |
| 21 | +``` |
| 22 | + |
| 23 | +— but it never disposes, closes, or otherwise releases `menuForm`. Grepping the |
| 24 | +whole `ShapeManager` partial class (`ShapeManager.cs` + `ShapeManagerMenu.cs`) turns |
| 25 | +up no `menuForm.Dispose()`/`.Close()` call anywhere. Every capture/annotation |
| 26 | +session that shows the toolbar leaks a full `Form` and its entire control tree — |
| 27 | +a real, non-trivial resource leak (not merely theoretical: `CreateToolbar` is called |
| 28 | +fresh each time the toolbar is (re)shown). |
| 29 | + |
| 30 | +**What the checker says (real oracle-sweep extractor output, `--flow-locals`, |
| 31 | +`--severity warning`):** |
| 32 | + |
| 33 | +```text |
| 34 | +ShapeManagerMenu.cs:47: [OWN001] IDisposable field 'menuForm' (type 'Form') is |
| 35 | + never disposed — its owner 'ShapeManager' leaks it (leak) [resource: disposable field] |
| 36 | +``` |
| 37 | + |
| 38 | +(plus one OWN001 per never-disposed ToolStrip child field — all transitively real, |
| 39 | +since `menuForm` itself is the actual leak root; see the sweep note for the full |
| 40 | +count.) Own.NET catches this correctly — cross-checked against the real source, no |
| 41 | +`Dispose()`/`Close()` call exists anywhere for `menuForm` in either partial-class |
| 42 | +file. |
| 43 | + |
| 44 | +**This `case.own`** models the shape generically: a class's `Dispose()` releases |
| 45 | +one owned resource (`history`, standing in for the real `HistoryStack`/`history` |
| 46 | +field) but never touches a second one it also owns (`menuForm`) — the plain |
| 47 | +owned-field-never-released OWN001, same core logic as the rest of the field-dispose |
| 48 | +corpus. As with the rest of the corpus, `case.own` is a hand reduction of the C# |
| 49 | +pattern (one representative field standing in for the ~38 that all share the same |
| 50 | +root cause), not a line-for-line transcription of `ShapeManagerMenu.cs`. |
| 51 | + |
| 52 | +**Draft verdict: true positive**, per the issue #201 sweep's triage guardrails |
| 53 | +(final TP/FP confirmation is the maintainer's call; this is not itself a bug report |
| 54 | +filed against ShareX upstream — see `docs/notes/mining.md`'s "reporting upstream is |
| 55 | +a separate, manual step"). |
0 commit comments