From 35395bba607e05ebd5e618e060f82134408a594c Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Wed, 18 Nov 2020 17:05:27 +0900 Subject: [PATCH] Keep unsafe.Pointer reference for handling of opInterface --- encode_vm.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/encode_vm.go b/encode_vm.go index 744e592..2a83ca0 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -216,6 +216,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, code *opcode) error { } seenPtr[ptr] = struct{}{} v := e.ptrToInterface(code, ptr) + ctx.keepRefs = append(ctx.keepRefs, unsafe.Pointer(&v)) rv := reflect.ValueOf(v) if rv.IsNil() { e.encodeNull() @@ -292,6 +293,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, code *opcode) error { } seenPtr[ptr] = struct{}{} v := e.ptrToInterface(code, ptr) + ctx.keepRefs = append(ctx.keepRefs, unsafe.Pointer(&v)) rv := reflect.ValueOf(v) if rv.IsNil() { e.encodeNull()