Skip to content

Free C strings passed to Objective-C in contact and attributed string… - #244

Open
tahodev wants to merge 1 commit into
mautrix:masterfrom
tahodev:fix/mac-cstring-leaks
Open

tahodev wants to merge 1 commit into
mautrix:masterfrom
tahodev:fix/mac-cstring-leaks

Conversation

@tahodev

@tahodev tahodev commented Oct 24, 2026

Copy link
Copy Markdown

Fixes #239, fixes #240.

The C.CString arguments in GetContactInfo (contacts.go) and meowDecodeAttributedString (attributedstring.go) were never freed: malloc'd memory that neither the Objective-C autorelease pool nor the Go GC will reclaim. Every contact lookup leaked len(identifier)+1 bytes, and every decoded attributedBody leaked its base64 copy.

This frees both strings with the standard defer C.free(unsafe.Pointer(...)) pattern and adds the stdlib.h include for free. These are the only three C.CString call sites in the package, so the audit is complete. The larger Objective-C side allocation growth noted in #239 (objects created without ARC) is intentionally out of scope, matching the reporter's own correction that -fobjc-arc doesn't apply here.

Verification: gofmt clean; root go build behaves identically before and after the change (it fails only on the missing libolm system dependency in my Linux environment, same as the clean baseline). I could not compile the darwin/cgo package locally (no macOS toolchain), so the change is reviewed mechanically — it follows the same C.free pattern the reporter proposed and that cgo documents.

AI assistance (various models) was used for this change.

… lookups

The C.CString arguments in GetContactInfo and meowDecodeAttributedString
were never freed, leaking len(identifier)+1 bytes per contact lookup and
the base64-encoded attributedBody per decoded message.

Fixes mautrix#239, fixes mautrix#240.
@tahodev
tahodev requested a review from tulir as a code owner October 24, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant