It won't flag any error whatsoever, actually, but if you don't free that allocation correctly it will not be freed until termination.
On Friday, 1 March 2019 06:36:50 UTC+1, Cholerae Hu wrote: > > Consider the following code: > ``` > package main > > /* > struct B { > int i; > }; > > struct A { > int j; > struct B b; > }; > */ > import "C" > > func NewA() *C.struct_A { > return &C.struct_A{ > j: 1, > b: C.struct_B{ > i: 2, > }, > } > } > > func main() { > a := NewA() > } > ``` > Will 'a' be scanned by go runtime? It is allocate by go runtime. > > However, if a pointer point to C.xxx will be scanned, consider the > following code: > ``` > package main > > // #include <stdlib.h> > import "C" > import ( > "runtime" > "unsafe" > ) > > func main() { > p := (*C.int)(C.malloc(8)) > C.free(unsafe.Pointer(p)) > runtime.GC() > } > ``` > If p is scanned, go runtime should throw a 'bad pointer' error, because > the memory pointed by p is allocated by C.malloc, not go runtime. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.