fix(v2/linux,darwin): plug Calloc leak caused by value receivers - #6083
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. WalkthroughThe Darwin and Linux ChangesCalloc lifecycle
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to 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: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation 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)
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. A rabbit found strings in a C-shaped haystack Comment |
leaanthony
left a comment
There was a problem hiding this comment.
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.
… plug Calloc leak caused by value receivers
Calloc.StringandCalloc.Freein the v2 linux and darwin frontends take the receiver by value, soStringappends eachC.CStringto a copy of the pool that is dropped on return. The caller's pool stays nil,Freeiterates nothing, and every string allocated for dialogs, menus, single-instance messaging and window setup leaks. On darwindefer c.Free()even captures the empty copy up front.NewCallocnow returns a pointer and both methods use pointer receivers, the same shape v3 already has inlinux_cgo.go. Call sites keepc := 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
Documentation