// Go string to C string
// The C string is allocated in the C heap using malloc.
// It is the caller's responsibility to arrange for it to be
// freed, such as by calling C.free (be sure to include stdlib.h
// if C.free is needed).
func C.CString(string) *C.char
The problem you encountered after append is because append will create a new underlying array if the current underlying array does not have enough capacity for the appended data. The garbage collector is then free to collect the old underlying array, making the pointer you gathered with unsafe no longer valid.