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

fix(v2/linux,darwin): plug Calloc leak caused by value receivers#6083
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
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