mirror of https://github.com/goccy/go-json.git
Merge pull request #60 from goccy/feature/fix-unexpected-free-pointer
Fix a bugs where pointers are unexpectedly freed
This commit is contained in:
commit
5ab988208f
|
@ -19,7 +19,12 @@ jobs:
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: go test -v ./
|
run: go test -v ./ -count=1
|
||||||
|
|
||||||
- name: Test with race detector
|
- name: Test with GC
|
||||||
run: go test -v -race ./
|
run: go test -v ./ -count=1
|
||||||
|
env:
|
||||||
|
GOGC: 1
|
||||||
|
|
||||||
|
# - name: Test with race detector
|
||||||
|
# run: go test -v -race ./ -count=1
|
||||||
|
|
|
@ -216,6 +216,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, code *opcode) error {
|
||||||
}
|
}
|
||||||
seenPtr[ptr] = struct{}{}
|
seenPtr[ptr] = struct{}{}
|
||||||
v := e.ptrToInterface(code, ptr)
|
v := e.ptrToInterface(code, ptr)
|
||||||
|
ctx.keepRefs = append(ctx.keepRefs, unsafe.Pointer(&v))
|
||||||
rv := reflect.ValueOf(v)
|
rv := reflect.ValueOf(v)
|
||||||
if rv.IsNil() {
|
if rv.IsNil() {
|
||||||
e.encodeNull()
|
e.encodeNull()
|
||||||
|
@ -292,6 +293,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, code *opcode) error {
|
||||||
}
|
}
|
||||||
seenPtr[ptr] = struct{}{}
|
seenPtr[ptr] = struct{}{}
|
||||||
v := e.ptrToInterface(code, ptr)
|
v := e.ptrToInterface(code, ptr)
|
||||||
|
ctx.keepRefs = append(ctx.keepRefs, unsafe.Pointer(&v))
|
||||||
rv := reflect.ValueOf(v)
|
rv := reflect.ValueOf(v)
|
||||||
if rv.IsNil() {
|
if rv.IsNil() {
|
||||||
e.encodeNull()
|
e.encodeNull()
|
||||||
|
|
|
@ -225,9 +225,6 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func initBig() {
|
func initBig() {
|
||||||
if len(jsonBig) > 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
n := 10000
|
n := 10000
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
n = 100
|
n = 100
|
||||||
|
|
Loading…
Reference in New Issue