Keep unsafe.Pointer reference for handling of opInterface

This commit is contained in:
Masaaki Goshima 2020-11-18 17:05:27 +09:00
parent 6a11c84d0c
commit 35395bba60
1 changed files with 2 additions and 0 deletions

View File

@ -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()