Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove autoreleasepool from newVZFileSerialPortAttachment #71

Merged
merged 1 commit into from
Oct 13, 2022

Conversation

cfergeau
Copy link
Contributor

If we use autoreleasepool, the error returned from
VZFileSerialPortAttachment:initWithURL will be freed before
newVZFileSerialPortAttachment returns. We want the caller to be able to
use it.

This fixes TestNonExistingFileSerialPortAttachment() which is
crashing before this commit:

% go test .
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x2 addr=0xcf6cce7eb130 pc=0x19e33a5a0]

runtime stack:
runtime.throw({0x100ce0ded?, 0x100ccf234?})
	/usr/local/go/src/runtime/panic.go:1047 +0x40 fp=0x16f293700 sp=0x16f2936d0 pc=0x100ba2870
runtime.sigpanic()
	/usr/local/go/src/runtime/signal_unix.go:819 +0x1e4 fp=0x16f293730 sp=0x16f293700 pc=0x100bb9754

goroutine 19 [syscall]:
runtime.cgocall(0x100ccf214, 0x14000040d98)
	/usr/local/go/src/runtime/cgocall.go:158 +0x54 fp=0x14000040d60 sp=0x14000040d20 pc=0x100b6fbc4
github.com/Code-Hex/vz/v2._Cfunc_convertNSError2Flat(0x6000022cb120)
	_cgo_gotypes.go:344 +0x3c fp=0x14000040d90 sp=0x14000040d60 pc=0x100ccc11c
github.com/Code-Hex/vz/v2.newNSError.func1(0x1010c0a68?)
	/Users/teuf/dev/vz/objcutil.go:234 +0x48 fp=0x14000040df0 sp=0x14000040d90 pc=0x100cccd58
github.com/Code-Hex/vz/v2.newNSError(0x0?)
	/Users/teuf/dev/vz/objcutil.go:234 +0x30 fp=0x14000040e80 sp=0x14000040df0 pc=0x100cccbe0
github.com/Code-Hex/vz/v2.NewFileSerialPortAttachment({0x100cd9765?, 0x100be659c?}, 0x68?)
	/Users/teuf/dev/vz/console.go:92 +0x104 fp=0x14000040f10 sp=0x14000040e80 pc=0x100ccc6c4
github.com/Code-Hex/vz/v2.TestNonExistingFileSerialPortAttachment(0x0?)
	/Users/teuf/dev/vz/error_test.go:10 +0x30 fp=0x14000040f60 sp=0x14000040f10 pc=0x100ccbf10
testing.tRunner(0x14000107040, 0x100d81878)
	/usr/local/go/src/testing/testing.go:1446 +0x10c fp=0x14000040fb0 sp=0x14000040f60 pc=0x100c2d10c
testing.(*T).Run.func1()
	/usr/local/go/src/testing/testing.go:1493 +0x2c fp=0x14000040fd0 sp=0x14000040fb0 pc=0x100c2de4c
runtime.goexit()
	/usr/local/go/src/runtime/asm_arm64.s:1165 +0x4 fp=0x14000040fd0 sp=0x14000040fd0 pc=0x100bd4834
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1493 +0x300
[snip]

This fixes #56

Which issue(s) this PR fixes:

Fixes #

Additional documentation

If we use autoreleasepool, the error returned from
VZFileSerialPortAttachment:initWithURL will be freed before
newVZFileSerialPortAttachment returns. We want the caller to be able to
use it.

This fixes TestNonExistingFileSerialPortAttachment() which is
crashing before this commit:

```
% go test .
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x2 addr=0xcf6cce7eb130 pc=0x19e33a5a0]

runtime stack:
runtime.throw({0x100ce0ded?, 0x100ccf234?})
	/usr/local/go/src/runtime/panic.go:1047 +0x40 fp=0x16f293700 sp=0x16f2936d0 pc=0x100ba2870
runtime.sigpanic()
	/usr/local/go/src/runtime/signal_unix.go:819 +0x1e4 fp=0x16f293730 sp=0x16f293700 pc=0x100bb9754

goroutine 19 [syscall]:
runtime.cgocall(0x100ccf214, 0x14000040d98)
	/usr/local/go/src/runtime/cgocall.go:158 +0x54 fp=0x14000040d60 sp=0x14000040d20 pc=0x100b6fbc4
github.com/Code-Hex/vz/v2._Cfunc_convertNSError2Flat(0x6000022cb120)
	_cgo_gotypes.go:344 +0x3c fp=0x14000040d90 sp=0x14000040d60 pc=0x100ccc11c
github.com/Code-Hex/vz/v2.newNSError.func1(0x1010c0a68?)
	/Users/teuf/dev/vz/objcutil.go:234 +0x48 fp=0x14000040df0 sp=0x14000040d90 pc=0x100cccd58
github.com/Code-Hex/vz/v2.newNSError(0x0?)
	/Users/teuf/dev/vz/objcutil.go:234 +0x30 fp=0x14000040e80 sp=0x14000040df0 pc=0x100cccbe0
github.com/Code-Hex/vz/v2.NewFileSerialPortAttachment({0x100cd9765?, 0x100be659c?}, 0x68?)
	/Users/teuf/dev/vz/console.go:92 +0x104 fp=0x14000040f10 sp=0x14000040e80 pc=0x100ccc6c4
github.com/Code-Hex/vz/v2.TestNonExistingFileSerialPortAttachment(0x0?)
	/Users/teuf/dev/vz/error_test.go:10 +0x30 fp=0x14000040f60 sp=0x14000040f10 pc=0x100ccbf10
testing.tRunner(0x14000107040, 0x100d81878)
	/usr/local/go/src/testing/testing.go:1446 +0x10c fp=0x14000040fb0 sp=0x14000040f60 pc=0x100c2d10c
testing.(*T).Run.func1()
	/usr/local/go/src/testing/testing.go:1493 +0x2c fp=0x14000040fd0 sp=0x14000040fb0 pc=0x100c2de4c
runtime.goexit()
	/usr/local/go/src/runtime/asm_arm64.s:1165 +0x4 fp=0x14000040fd0 sp=0x14000040fd0 pc=0x100bd4834
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1493 +0x300
[snip]
```

This fixes Code-Hex#56
@Code-Hex Code-Hex merged commit 3bc9d1c into Code-Hex:master Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code-Hex/vz segfaults when NewFileSerialPortAttachment returns an error
2 participants