On Wed, May 22, 2019 at 8:34 PM Steven Estes <est...@yottadb.com> wrote:
>
> At this point, it seems, since there were no more references to the passed-in 
> Golang structures and the C pointers we had pulled out of them had been 
> morphed to uintptr values, that the Golang structures became eligible for 
> garbage collection. But because there was a Finalizer set for these 
> structures, the C storage was released when we were not finished with it yet 
> – in fact had not even made the call yet to the C routine.
>
> We got errors in the C code and saw that though the structures were 
> well-formed in the Go routine, the stuff that ended up being passed in was 
> complete garbage.
>
> We “fixed” this issue by putting a meaningless reference to the golang 
> variadic list that held all these values just prior to returning from the 
> routine which kept them from being garbage collected such that it ran 
> successfully.

You should be using runtime.KeepAlive.  That's what it's for.  When
you put a finalizer on a Go pointer that points to a C pointer, and
the finalizer frees the C pointer, and you pass the C pointer to C
code, then you must be careful to use runtime.KeepAlive on the Go
pointer after every single call where it passes the C pointer into C.

Ian

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcU%2BMkn-x2VnMjdE2t68rZjb3G-Xt1BU4H8_jZfJZPV90A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to