-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime: marked free object in span on Windows #45364
Comments
Unfortunately, you are falling afoul of the rules about storing Go pointers in C memory. https://golang.org/pkg/cmd/cgo/#hdr-Passing_pointers Running your program with GODEBUG=cgocheck=2 reports a violation.
I'm not sure what exactly the problem is here, though, as you're only reading from a possibly stale pointer. I'm not sure how exactly the pointer comes back to life on the Go side. But it is definitely unsafe to rely on the contents of the Go memory in |
The C code is just copy Go memory block passed in, it doesn't store go pointer and never pass it back to go. |
Writes a Go pointer into C memory. |
Sorry, i missed that line. Will it be ok if i reset |
No, I don't think so. It's not the content of C memory itself (Go never looks at such memory), it's the validity of the You probably need to arrange the Go pointer to reach the C code as an argument to a cgo function, not an element of a C-allocated structure. Or do the copy in Go (not sure what your end goal is - that may or may not be feasible). Closing, as this is not a bug in Go. If you have more questions, probably your best resource is to use one of the resources here: https://github.com/golang/go/wiki/Questions |
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?
I'm cross compile from macOS to windows with mingw,
the code is just like the sample here, passing a go memory pointer to C code and copy it,
the problem is that when
malloc
returns a reused memory block, it contains the original go memory pointer,which cause the gc to crash with this invalid pointer.
if i replace
malloc
withcalloc
then the crash is gone.Unfortunately i can only reproduce it in my own real code.
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: