yanyiwu / gojieba

"结巴"中文分词的Golang版本
MIT License
2.45k stars 303 forks source link

内存释放有异常。当我操作了jieba.Free()。然后开始将一个50M的对象json marshal后存储到file中。程序会报错 #122

Open ivory2406 opened 3 months ago

ivory2406 commented 3 months ago

----报错信息 double free or corruption (out) SIGABRT: abort PC=0x7f83c2ca9acf m=7 sigcode=18446744073709551610 signal arrived during cgo execution

goroutine 5 [syscall]: runtime.cgocall(0x52cff0, 0xc0000665b8) /root/.go/go1.20/src/runtime/cgocall.go:157 +0x5c fp=0xc000066590 sp=0xc000066558 pc=0x40d6bc github.com/yanyiwu/gojieba._Cfunc_FreeJieba(0x1b2c830) _cgo_gotypes.go:204 +0x45 fp=0xc0000665b8 sp=0xc000066590 pc=0x52a525 github.com/yanyiwu/gojieba.(Jieba).Free.func1(0x7f83c3f47108?) /root/.go/go1.21.6/pkg/mod/github.com/yanyiwu/gojieba@v1.4.2/jieba.go:53 +0x3a fp=0xc0000665f0 sp=0xc0000665b8 pc=0x52b07a github.com/yanyiwu/gojieba.(Jieba).Free(0x0?) /root/.go/go1.21.6/pkg/mod/github.com/yanyiwu/gojieba@v1.4.2/jieba.go:53 +0x19 fp=0xc000066608 sp=0xc0000665f0 pc=0x52b019 runtime.call16(0x0, 0x580408, 0xc0344d62d0, 0x10, 0x10, 0x10, 0xc0000666c0) /root/.go/go1.20/src/runtime/asm_amd64.s:728 +0x49 fp=0xc000066628 sp=0xc000066608 pc=0x4701c9 runtime.runfinq() /root/.go/go1.20/src/runtime/mfinal.go:255 +0x3c5 fp=0xc0000667e0 sp=0xc000066628 pc=0x421905 runtime.goexit() /root/.go/go1.20/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc0000667e8 sp=0xc0000667e0 pc=0x471ea1 created by runtime.createfing /root/.go/go1.20/src/runtime/mfinal.go:163 +0x45

-----使用方式

func (jbt *JiebaTokenizer) refreshJieba() {
    if jbt.Jieba != nil {
        jbt.Jieba.Free()
    }

    jbt.Jieba = gojieba.NewJieba()
}

func (t *temp) DownloadParams(paramsFileDownloadPath string) error {
  // xx是我下载的一个很大的对象
    jsonData, err := json.MarshalIndent(xx, "", "  ")
    if err != nil {
        return err
    }

    err = os.WriteFile(paramsFileDownloadPath, jsonData, os.ModePerm)
    if err != nil {
        return err
    }

    return nil
}
yanyiwu commented 3 months ago

你的意思是free后,另一个和gojieba无关的对象操作时就会报错。如果不free的话就不会报错,是么?

ivory2406 commented 4 weeks ago

是的。我就把free先暂时去掉了