cmd/cgo: memory sanitizer error due to uninitialized memory in C.CString when using cgo with sanitizers enabled #60912
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Sample repo: https://github.com/bc-lee/test-golang-cgo-sanitizers
To reproduce, run the following commands on linux x86_64:
Basically, I'm making a executable with cgo, with address/memory sanitizers enabled C libraries.
I checked out Chromium's LLVM build and sysroot to build the executable.
The main code is as follows:
From my understanding,
C.Cstring
allocates a memory(usingmalloc
) and returns a pointer to it. So I'm callingC.free
to free the memory.However when I run the executable, I get the following error:
It seems that msan treats the memory allocated by
C.CString
as uninitialized.I'm not sure if this is a bug, or golang currently does not support this kind of use case, or I'm doing something wrong.
What did you expect to see?
No error.
What did you see instead?
Memory sanitizer error.
The text was updated successfully, but these errors were encountered: