If, after using a wasmer instance, the garbage collector runs, it sweeps the instance and causes the program to crash when calling wasm functions with a segmentation fault.
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x7f9d78702263 pc=0x7f9d78702263]
due to instance having been garbage collected.
Additional context
I suggest adding defer instance.Close() to the example at https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer. This will prevent the bug but only because a reference to instance is kept, not because the instance.Close() function does anything to prevent it.
Thanks for the bug report!
Describe the bug
If, after using a wasmer instance, the garbage collector runs, it sweeps the instance and causes the program to crash when calling wasm functions with a segmentation fault.
Steps to reproduce
runtime.GC()
right below thesum, err := instance.Exports.GetFunction("sum")
lineExpected behavior
Program runs and finishes as normal
Actual behavior
You get a segmentation fault:
due to instance having been garbage collected.
Additional context
I suggest adding
defer instance.Close()
to the example at https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer. This will prevent the bug but only because a reference to instance is kept, not because theinstance.Close()
function does anything to prevent it.