Issues with the Go memory management code were hacked around by adding a
new check that ensured that pointers to memory managed by Go are never
passed to cgo code, since one can not be sure how and where pointers to
Go memory are being stored in the C code.
As a result, the memory must be manually malloc'd and free'd by cgo,
even if it's a Go object in the C memory. The userdata fix makes this
change explicit, by running a malloc and free using cgo, to explicitly
control the memory management.
Discussion at:
Issues with the Go memory management code were hacked around by adding a new check that ensured that pointers to memory managed by Go are never passed to cgo code, since one can not be sure how and where pointers to Go memory are being stored in the C code.
As a result, the memory must be manually malloc'd and free'd by cgo, even if it's a Go object in the C memory. The userdata fix makes this change explicit, by running a malloc and free using cgo, to explicitly control the memory management.