diff options
| author | Ian Lance Taylor <iant@golang.org> | 2016-06-01 15:24:14 -0700 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2016-06-03 20:51:39 +0000 |
| commit | 7b48020cfeb64d1f841a7523aa841dbe53b3b465 (patch) | |
| tree | 5e36f2031243cd5d9ee4a5a74dcccc2d64347bfc /misc/cgo/errors | |
| parent | 55559f159e4ba7645a864c89caba0e29498425f9 (diff) | |
| download | go-7b48020cfeb64d1f841a7523aa841dbe53b3b465.tar.xz | |
cmd/cgo: check pointers for deferred C calls at the right time
We used to check time at the point of the defer statement. This change
fixes cgo to check them when the deferred function is executed.
Fixes #15921.
Change-Id: I72a10e26373cad6ad092773e9ebec4add29b9561
Reviewed-on: https://go-review.googlesource.com/23650
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'misc/cgo/errors')
| -rw-r--r-- | misc/cgo/errors/ptr.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/misc/cgo/errors/ptr.go b/misc/cgo/errors/ptr.go index 27eb78e36c..e39f0413e4 100644 --- a/misc/cgo/errors/ptr.go +++ b/misc/cgo/errors/ptr.go @@ -314,6 +314,14 @@ var ptrTests = []ptrTest{ body: `i := 0; p := S{u:uintptr(unsafe.Pointer(&i))}; q := (*S)(C.malloc(C.size_t(unsafe.Sizeof(p)))); *q = p; C.f(unsafe.Pointer(q))`, fail: false, }, + { + // Check deferred pointers when they are used, not + // when the defer statement is run. + name: "defer", + c: `typedef struct s { int *p; } s; void f(s *ps) {}`, + body: `p := &C.s{}; defer C.f(p); p.p = new(C.int)`, + fail: true, + }, } func main() { |
