Skip to content

fix(v2/linux,darwin): plug Calloc leak caused by value receivers - #6083

Merged
leaanthony merged 2 commits into
wailsapp:masterfrom
4RH1T3CT0R7:fix/v2-calloc-pool-receiver
Sep 8, 2026
Merged

leaanthony merged 2 commits into
wailsapp:masterfrom
4RH1T3CT0R7:fix/v2-calloc-pool-receiver

Conversation

@4RH1T3CT0R7

@4RH1T3CT0R7 4RH1T3CT0R7 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Calloc.String and Calloc.Free in the v2 linux and darwin frontends take the receiver by value, so String appends each C.CString to a copy of the pool that is dropped on return. The caller's pool stays nil, Free iterates nothing, and every string allocated for dialogs, menus, single-instance messaging and window setup leaks. On darwin defer c.Free() even captures the empty copy up front.

NewCalloc now returns a pointer and both methods use pointer receivers, the same shape v3 already has in linux_cgo.go. Call sites keep c := NewCalloc(); defer c.Free() unchanged. The windows frontend has no cgo allocator and is unaffected. Changelog entry added under Unreleased.

Fixes #6059
Fixes #6058

Summary by CodeRabbit

  • Bug Fixes

    • Fixed a memory leak affecting C strings used during dialog, menu, and window setup on macOS and Linux.
  • Documentation

    • Added an unreleased changelog entry describing the memory-leak fix.

String appended each C.CString to a copy of the receiver, so the
caller's pool stayed nil and Free had nothing to release. Every string
allocated for dialogs, menus, single instance and window setup leaked.
Return a pointer from NewCalloc and use pointer receivers, matching v3.

Fixes wailsapp#6059
Fixes wailsapp#6058
@github-actions github-actions Bot added Documentation Improvements or additions to documentation MacOS Linux v2-only labels Sep 6, 2026
@coderabbitai

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 79e30b17-6e60-4e15-af1a-c106c1553fdb

📥 Commits

Reviewing files that changed from the base of the PR and between 5bce785 and b39d41c.

📒 Files selected for processing (3)
  • v2/internal/frontend/desktop/darwin/calloc.go
  • v2/internal/frontend/desktop/linux/calloc.go
  • website/src/pages/changelog.mdx

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


Walkthrough

The Darwin and Linux Calloc implementations now use pointer-based allocation pools. The changelog documents the resulting C-string memory-leak fix.

Changes

Calloc lifecycle

Layer / File(s) Summary
Pointer-backed allocator lifecycle
v2/internal/frontend/desktop/{darwin,linux}/calloc.go, website/src/pages/changelog.mdx
NewCalloc returns *Calloc, and String and Free use pointer receivers so allocated C strings remain in the shared pool until cleanup. The changelog records the fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 54281

Darwin and Linux C-string allocations are now retained by the shared allocator and released during cleanup, fixing the reported frontend memory leak with no remaining merge-blocking risk.

Suggested reviewers: leaanthony

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug, affected platforms, implementation, linked issues, and call-site compatibility. It does not include the required change type, testing details, test configuration, or … Add the required description sections. Select the applicable change type, document tests and platform details, provide wails doctor output or environment details, and complete the checklist.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Linux and Darwin Calloc memory leak fix caused by value receivers.
Linked Issues check ✅ Passed The changes satisfy both linked issues [#6059] and [#6058]. The Linux and Darwin implementations now return *Calloc and use pointer receivers, which preserves allocations in the pool and allows `Fre…
Out of Scope Changes check ✅ Passed All changes are within scope. The code changes fix the linked Linux and Darwin memory leaks, and the Unreleased changelog entry documents the fix.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 …
Full details: Description check

Explanation

The description explains the bug, affected platforms, implementation, linked issues, and call-site compatibility. It does not include the required change type, testing details, test configuration, or checklist responses.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit found strings in a C-shaped haystack
Pointer paws kept each one on the track
The pool held them tight
Then freed them just right
No leaks hopped away through a crack

Comment @coderabbitai help to get the list of available commands.

@leaanthony leaanthony left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the allocator change and native string lifetimes. Pointer receivers fix allocation tracking and deferred cleanup on both v2 platforms; the changelog entry is included. Required checks pass. The equivalent v3 GTK4 and GTK3 fixes are already present from #5466.

@leaanthony
leaanthony merged commit e75c10f into wailsapp:master Sep 8, 2026
33 of 34 checks passed
leaanthony pushed a commit that referenced this pull request Sep 8, 2026
… plug Calloc leak caused by value receivers
nadaverell added a commit to skyhook-io/radar that referenced this pull request Sep 23, 2026
Batches this week's soaked, low-risk Dependabot updates into one tested
PR. One update is excluded because it breaks Radar's MCP private-mount
handshake.

**Screening time:** 2026-09-23T09:42:55Z · **72h cutoff:** published at
or before 2026-09-20T09:42:55Z. Ages are measured from the upstream
publication time (npm registry / Go module proxy), not from when
Dependabot opened the PR.

## Included (9)

| PR | Dependency | Old → New | Published (UTC) | Soak | Risk conclusion
|
|---|---|---|---|---|---|
| #1860 | github.com/cilium/cilium | 1.20.1 → 1.20.2 | 2026-09-15 18:52
| 7.6d | Radar imports only `api/v1/observer` + `api/v1/flow`
(`internal/traffic/hubble.go`). Those generated files differ only in the
protoc version comment. The release contains Hubble Relay/agent fixes
that don't touch the client API. |
| #1858 | google.golang.org/grpc | 1.83.2 → 1.84.0 | 2026-09-17 20:03 |
5.6d | Only used for the Hubble client (`grpc`, `credentials`,
`credentials/insecure`). The one behavior change renames the
`stats/otel` pick_first metrics, which Radar doesn't use. Also fixes a
client that could stay stuck in IDLE after an RPC was canceled during
stream creation. |
| #1856 | github.com/wailsapp/wails/v2 | 2.15.0 → 2.16.0 | 2026-09-14
09:13 | 9.0d | The only v2 source change fixes a `Calloc` leak on
darwin/linux: the value receiver becomes a pointer receiver, so `Free()`
now actually frees. I checked for use-after-free: the ObjC side copies
every string into an `NSString` (`safeInit`) synchronously before Go
frees it. No v2.16.0 regressions reported upstream. |
| #1854 | helm.sh/helm/v3 | 3.21.4 → 3.22.0 | 2026-09-09 22:21 | 13.5d |
Upstream calls it "primarily dependency updates and k8s-io group to
0.37.0", which matches Radar's k8s 0.37.0. Also fixes the registry token
scope for `helm push`. The last Helm 3 minor release. |
| #1857 | @tanstack/react-query (+ query-core) | 5.102.8 → 5.103.1 |
2026-09-16 15:01 | 7.8d | #11502 changes filter matching: a filter key
with trailing `undefined` no longer matches a shorter query key. I
audited all 149 invalidate/remove/cancel/setQueriesData call sites.
Radar's query keys are fixed-length (the only spread key,
`workloadMetrics.ts`, is fixed-length too), so no invalidation changes.
|
| #1855 | @types/node | 26.2.0 → 26.6.2 | 2026-09-19 00:11 | 4.4d |
Type-only change, covered by `make tsc`. Bumped in both `web/` and
`packages/k8s-ui/`. |
| #1861 | prettier | 3.9.5 → 3.9.8 | 2026-09-17 21:41 | 5.5d | Dev-only
formatter (`npm run format`), not run in CI. Before/after check: 3.9.5
and 3.9.8 flag the identical set of 304 files in `web/src`, so
formatting output is unchanged. |
| #1859 | react-router-dom (+ react-router) | 7.18.3 → 7.18.4 |
2026-09-15 15:05 | 8.0d | Two fixes: RSC redirect escaping (Radar
doesn't use RSC) and avoiding `startViewTransition` during
hydration/revalidate. Radar doesn't use view transitions. |
| #1862 | tailwind-merge | 3.6.0 → 3.7.0 | 2026-09-12 20:10 | 10.6d |
Nothing in `web/src` or `packages/*/src` imports it. It's only declared
as a peer/dev dependency, so the bundle doesn't change. |

## Excluded / held (1, left open)

- **#1776 github.com/modelcontextprotocol/go-sdk 1.6.1 → 1.8.0**
(excluded for risk). The PR's own CI fails
`TestInvestigationHandlerAnnotatesRealToolCallWithoutChangingPublicContract`
with `private mount handshake did not mark the scope connected`
(`internal/mcp/server_investigation_test.go:253`). This is a real change
in how the SDK's handshake behaves against Radar's investigation-scope
mount, not flakiness. Adopting it needs a Radar source change, which
should be a separate follow-up PR.

## Resolver movement beyond the PR targets

- **npm resolver floated past two targets, now pinned back:** a plain
lockfile refresh resolved `@tanstack/react-query`/`query-core`
**5.103.2** (published 2026-09-21T09:33Z, under 72h) and `prettier`
**3.9.9** (published 2026-09-23T06:31Z, about 3h). The lockfile is
pinned to the soaked targets 5.103.1 and 3.9.8.
- **npm transitive:** `undici-types` 8.3.0 → 8.9.0. It's required by
`@types/[email protected]` (`~8.9.0`), is type-only, and was published
2026-07-24.
- **Go, compiled graph (in go.mod):** `santhosh-tekuri/jsonschema/v6`
6.0.2 → 6.0.3 (2026-06-28, via Helm) and `genproto/googleapis/{api,rpc}`
→ `v0.0.0-20260706201446` (2026-07-06, via gRPC). All are well past 72h.
- **Go, module-graph-only (in `go list -m all`, not in go.mod):**
`cloud.google.com/go/auth` 0.20.0, `gax-go/v2` 2.22.0,
`enterprise-certificate-proxy` 0.3.15, `google.golang.org/api` 0.278.0,
`detectors/gcp` 1.34.0, `cilium/statedb` 0.8.4, `felixge/httpsnoop`
1.1.0, `go-shellwords` 1.0.14, `x/telemetry` 2026-06-25,
`k8s.io/endpointslice` 0.36.4, `gateway-api/conformance` 1.6.2.
`phayes/freeport` was dropped. All were published between 2026-04-06 and
2026-09-03.
- **go.mod bookkeeping:** `go mod tidy` moves `google/jsonschema-go` and
`opencontainers/go-digest` from `// indirect` to direct. `main` was
already untidy here (Radar imports both directly), and every Dependabot
Go PR showed the same change. Versions are unchanged.

## Verification

- `go mod verify`: all modules verified
- `make tsc`: pass
- `make test` (`go test ./...`): pass, 41 packages ok
- `pkg/` module `go test ./...`: pass
- `web` vitest: 127 files / 1497 tests pass
- `packages/k8s-ui` vitest: 199 files / 3841 pass, 1 skipped
- `make build`: pass
- `make desktop-binary` (Wails, darwin/arm64): pass. The app was
launched and stayed up for 10s with no crash or signal, which exercises
the changed window/menu string-free path.
- Targeted `go test -count=1` for `internal/traffic` (Hubble/gRPC),
`internal/helm`, `internal/cloudinstall`, `internal/mcp`: pass
- Prettier before/after: identical drift set (304/304)
- `git diff --check`: clean. The diff touches only `go.mod`, `go.sum`,
`package-lock.json`, `web/package.json`, and
`packages/k8s-ui/package.json`.
- **Not verified:** the Linux/Windows desktop builds (Wails needs cgo
and a GTK/WebView2 toolchain). The Wails fix also covers linux
`window.go`, which frees after `gtk` calls that copy their string
arguments.
- **visual-test: skipped.** The runtime frontend changes are two
patch-level fixes (react-router view transitions/RSC, react-query key
matching) that don't affect how Radar renders anything, and
tailwind-merge isn't imported.

## Upstream sources

- grpc-go v1.84.0: https://github.com/grpc/grpc-go/releases/tag/v1.84.0
- Helm v3.22.0: https://github.com/helm/helm/releases/tag/v3.22.0
- Cilium v1.20.2: https://github.com/cilium/cilium/releases/tag/v1.20.2
- Wails v2.16.0 changelog:
https://github.com/wailsapp/wails/blob/v2.16.0/website/src/pages/changelog.mdx
(fix: wailsapp/wails#6083)
- TanStack Query:
https://github.com/TanStack/query/releases/tag/%40tanstack%2Fquery-core%405.103.0,
https://github.com/TanStack/query/releases/tag/%40tanstack%2Fquery-core%405.103.1
- React Router 7.18.4:
https://github.com/remix-run/react-router/blob/v7/CHANGELOG.md#v7184
- tailwind-merge 3.7.0:
https://github.com/dcastil/tailwind-merge/releases/tag/tailwind-merge%403.7.0
- Prettier 3.9.6–3.9.8:
https://github.com/prettier/prettier/blob/3.9.8/CHANGELOG.md

Supersedes #1854, #1855, #1856, #1857, #1858, #1859, #1860, #1861, #1862

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Dependency-only updates with explicit soak notes and broad test
coverage; MCP SDK was held back due to a known handshake regression.
> 
> **Overview**
> Batches nine **soaked** dependency bumps into one PR after screening;
**modelcontextprotocol/go-sdk** is intentionally **not** included
because it breaks Radar’s MCP private-mount handshake.
> 
> **Go:** bumps **cilium** (1.20.1→1.20.2), **grpc** (1.83.2→1.84.0),
**Wails v2** (2.15.0→2.16.0), and **Helm v3** (3.21.4→3.22.0), plus
transitive refreshes in `go.sum`. **`go mod tidy`** also promotes
**`google/jsonschema-go`** and **`opencontainers/go-digest`** from
indirect to **direct** `require` entries (versions unchanged).
> 
> **Frontend:** bumps **@tanstack/react-query** (5.103.1),
**@types/node** (26.6.2 in `web/` and `packages/k8s-ui/`), **prettier**
(3.9.8), **react-router-dom** (7.18.4), and **tailwind-merge** (3.7.0),
with matching **`package-lock.json`** updates. The lockfile pins soaked
targets (e.g. not floating to newer query/prettier releases) and drops
many `"peer": true` metadata flags on nested packages.
> 
> No application source changes—only module manifests and lockfiles.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
04f558f. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation Linux MacOS v2-only

Projects

None yet

2 participants