You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found a related-but-different problem when investigating issue #13830.
Making the _cgoCheckPointer call explicitly in the function parameters of a deferred call causes the pointer check to occur at the wrong time. We end up checking whether the argument had a Go pointer at the point where the call was deferred, not whether the argument had a Go pointer at the point where the C call was actually made.
Consider this program:
package main
/*#include <stdint.h>struct sneaky { int *p;};void sneak(struct sneaky *s, uintptr_t *u) { *u = (uintptr_t)(s->p);}*/import"C"import"fmt"funcmain() {
vars C.struct_sneakyvaru C.uintptr_tdeferfunc() { fmt.Println(u) }()
deferC.sneak(&s, &u)
varescapee C.ints.p=&escapee
}
With go version go1.6.1 linux/amd64, the program (incorrectly) prints a leaked address and exits with code 0.
Changing the call to C.sneak to an explicit call at the end of main causes the program to (correctly) panic with a cgo pointer violation.
The problem is that the _cgoCheckPointer calls wrap the function's arguments, not the function call itself:
The text was updated successfully, but these errors were encountered:
bcmills
changed the title
cmd/cgo: _cgoCheckPointer call occurs at wrong time for deferred function calls.
cmd/cgo: _cgoCheckPointer call occurs to early for deferred function calls.
Jun 1, 2016
bcmills
changed the title
cmd/cgo: _cgoCheckPointer call occurs to early for deferred function calls.
cmd/cgo: _cgoCheckPointer call occurs too early for deferred function calls.
Jun 1, 2016
I found a related-but-different problem when investigating issue #13830.
Making the _cgoCheckPointer call explicitly in the function parameters of a deferred call causes the pointer check to occur at the wrong time. We end up checking whether the argument had a Go pointer at the point where the call was deferred, not whether the argument had a Go pointer at the point where the C call was actually made.
Consider this program:
With go version go1.6.1 linux/amd64, the program (incorrectly) prints a leaked address and exits with code 0.
Changing the call to
C.sneak
to an explicit call at the end ofmain
causes the program to (correctly) panic with a cgo pointer violation.The problem is that the _cgoCheckPointer calls wrap the function's arguments, not the function call itself:
The text was updated successfully, but these errors were encountered: