Skip to content

Commit c06c99f

Browse files
authored
Merge branch 'main' into claude/own-net-issue-209-ownignore
2 parents e33c0a7 + c029e8d commit c06c99f

18 files changed

Lines changed: 1265 additions & 93 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,8 @@ jobs:
760760
dotnet run --project frontend/roslyn/OwnSharp.Extractor -- \
761761
frontend/roslyn/samples/FlowLocalsSample.cs \
762762
frontend/roslyn/samples/MemoryOwnerEscapeSample.cs \
763-
frontend/roslyn/samples/FactoryLeakSample.cs --flow-locals -o "$RUNNER_TEMP/flow.json"
763+
frontend/roslyn/samples/FactoryLeakSample.cs \
764+
frontend/roslyn/samples/OverloadSigSample.cs --flow-locals -o "$RUNNER_TEMP/flow.json"
764765
out=$(python -m ownlang ownir "$RUNNER_TEMP/flow.json" || true)
765766
echo "$out"
766767
echo "$out" | grep -q "OWN002" || { echo "FAIL: expected OWN002 (use-after-dispose)"; exit 1; }
@@ -949,6 +950,39 @@ jobs:
949950
for ok in factoryOk made; do
950951
if echo "$out" | grep -q "'$ok'"; then echo "FAIL: D5.2 silent case '$ok' was reported"; exit 1; fi
951952
done
953+
# Interprocedural stage 2 (spec/OwnIR.md §5.1): per-overload signature keys.
954+
# SigOverloads.Open is overloaded — the (string) overload is a fresh factory,
955+
# the (FileStream,bool) one returns its parameter — so the name-merged returns
956+
# DISAGREE (no fresh claim). The `sig` stamped on both the functions[] records
957+
# and the call op resolves the fresh overload's OWN summary, so the dropped
958+
# stream in Drop surfaces as OWN001 at the call — the recall the merge lost.
959+
# Structural check (CodeRabbit): pin BOTH sides of the edge exactly — the two
960+
# overload records' sigs AND the Drop call op's callee/sig/result — so a
961+
# missing or unmatched CALL-side sig fails here by itself, not only via the
962+
# downstream finding.
963+
python3 - "$RUNNER_TEMP/flow.json" <<'PY'
964+
import json, sys
965+
facts = json.load(open(sys.argv[1]))
966+
fns = facts.get("functions", [])
967+
sigs = sorted(str(f.get("sig")) for f in fns
968+
if f.get("name") == "SigOverloads.Open")
969+
assert sigs == ["System.IO.FileStream,System.Boolean", "System.String"], \
970+
f"overload record sigs wrong: {sigs}"
971+
calls = [op for f in fns if f.get("name") == "SigOverloads.Drop"
972+
for op in f.get("body", []) if op.get("op") == "call"]
973+
assert any(c.get("callee") == "SigOverloads.Open"
974+
and c.get("sig") == "System.String"
975+
and c.get("result") == "dropped" for c in calls), \
976+
f"Drop call op missing the (string) overload sig: {calls}"
977+
print("OK: stage-2 sig stamped on both sides of the Drop edge")
978+
PY
979+
echo "$out" | grep -qE "OverloadSigSample\.cs:[0-9]+:.*\[OWN001\].*'dropped' is never disposed" \
980+
|| { echo "FAIL: expected the sig-resolved fresh-overload leak (OWN001 on 'dropped')"; exit 1; }
981+
# the factory itself (transfers out via return), the non-fresh overload's
982+
# balanced probe, and the fresh local it returns all stay silent.
983+
for ok in opened probe; do
984+
if echo "$out" | grep -q "'$ok'"; then echo "FAIL: stage-2 silent case '$ok' was reported"; exit 1; fi
985+
done
952986
echo "OK: flow-sensitive OWN001/002/003 on real C# (path-sensitive, loops via while/foreach/for, try/finally sequential, never-vs-every-path wording, dispose-optional exempt, beyond flat)"
953987
- name: Gallery C#-native bad/ok pairs (examples/gallery/cs/)
954988
run: |
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Fix: Dispose() also disposes menuForm (a Form is IDisposable; disposing it
2+
// tears down its whole child-control tree, per WinForms' own Control.Dispose
3+
// semantics — see field-notes-patterns.md for that transitive-disposal idiom).
4+
using System;
5+
using System.Windows.Forms;
6+
7+
internal sealed class ShapeManager : IDisposable
8+
{
9+
private Form menuForm;
10+
private readonly HistoryStack history = new HistoryStack();
11+
12+
internal void CreateToolbar()
13+
{
14+
menuForm = new Form { ShowInTaskbar = false };
15+
menuForm.Show();
16+
}
17+
18+
public void Dispose()
19+
{
20+
history.Dispose();
21+
menuForm?.Dispose();
22+
}
23+
}
24+
25+
internal sealed class HistoryStack : IDisposable
26+
{
27+
public void Dispose() { }
28+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Reduced from ShareX/ShareX @ 0df9ca4, ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs
2+
// (CreateToolbar, ~lines 62-1246) and ShapeManager.cs:2406-2411 (Dispose) — found by
3+
// the issue #201 oracle sweep.
4+
//
5+
// ShapeManager builds its on-screen annotation toolbar as a plain WPF-Forms `Form`
6+
// (`menuForm`) hosting a `ToolStripEx` with ~38 buttons/menu items/numeric-updowns/
7+
// combo-boxes, all created and owned by this class. `ShapeManager.Dispose()` exists
8+
// and disposes some of what the class owns (`history`), but forgets `menuForm`
9+
// entirely — every capture/annotation session leaks a full `Form` plus its whole
10+
// toolbar tree, because nothing else ever closes or disposes it either.
11+
using System;
12+
using System.Windows.Forms;
13+
14+
internal sealed class ShapeManager : IDisposable
15+
{
16+
private Form menuForm;
17+
private readonly HistoryStack history = new HistoryStack();
18+
19+
internal void CreateToolbar()
20+
{
21+
menuForm = new Form { ShowInTaskbar = false };
22+
// ...builds tsMain and ~38 ToolStrip child items, all added to menuForm...
23+
menuForm.Show();
24+
}
25+
26+
public void Dispose()
27+
{
28+
// real code also calls DeleteAllShapes(); irrelevant to the leak.
29+
history.Dispose();
30+
// menuForm is never disposed or closed anywhere in this class.
31+
}
32+
}
33+
34+
internal sealed class HistoryStack : IDisposable
35+
{
36+
public void Dispose() { }
37+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// OwnLang model of the ShareX ShapeManager.menuForm leak (issue #201 oracle
2+
// sweep): a class's Dispose() disposes some of its owned resources (`history`)
3+
// but forgets one it itself created (`menuForm`) — a plain owned-field leak,
4+
// the generic OWN001 acquire-with-no-release. See notes.md for the real finding.
5+
module Corpus
6+
resource Form {
7+
acquire create
8+
release dispose
9+
kind "disposable"
10+
}
11+
resource HistoryStack {
12+
acquire create
13+
release dispose
14+
kind "disposable"
15+
}
16+
fn Dispose(unused: int) {
17+
let menuForm = acquire Form(unused); // CreateToolbar(): menuForm = new Form { ... }
18+
let history = acquire HistoryStack(unused);
19+
release history; // Dispose(): history.Dispose()
20+
// no `release menuForm;` — Dispose() never touches menuForm (OWN001)
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OWN001
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)