From 5e5c84ba27e8a46fce9cd1bdc7d28a938e544021 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Tue, 20 Aug 2024 18:06:01 +0800 Subject: [PATCH] llcppsigfetch:json memory free --- chore/_xtool/llcppsigfetch/llcppsigfetch.go | 10 ++++++---- chore/_xtool/llcppsigfetch/parse/cvt_test/cvt.go | 8 ++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/chore/_xtool/llcppsigfetch/llcppsigfetch.go b/chore/_xtool/llcppsigfetch/llcppsigfetch.go index 9c3cd6b3..6f9dcd37 100644 --- a/chore/_xtool/llcppsigfetch/llcppsigfetch.go +++ b/chore/_xtool/llcppsigfetch/llcppsigfetch.go @@ -22,9 +22,9 @@ import ( "os" "path/filepath" "strings" - "unsafe" "github.com/goplus/llgo/c" + "github.com/goplus/llgo/c/cjson" "github.com/goplus/llgo/chore/_xtool/llcppsigfetch/parse" "github.com/goplus/llgo/chore/_xtool/llcppsymg/config" ) @@ -78,7 +78,9 @@ func getHeaderFiles(cflags string, files []string) []string { } func outputInfo(context *parse.Context) { - output := context.Output().Print() - defer c.Free(unsafe.Pointer(output)) - c.Printf(output) + info := context.Output() + str := info.Print() + defer cjson.FreeCStr(str) + defer info.Delete() + c.Printf(str) } diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/cvt.go b/chore/_xtool/llcppsigfetch/parse/cvt_test/cvt.go index 3b59cd85..974a4bb7 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/cvt.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/cvt.go @@ -2,6 +2,7 @@ package cvttest import ( "github.com/goplus/llgo/c" + "github.com/goplus/llgo/c/cjson" "github.com/goplus/llgo/chore/_xtool/llcppsigfetch/parse" ) @@ -20,9 +21,12 @@ func RunTest(testName string, testCases []string) { panic(err) } - json := converter.MarshalASTFiles() - c.Printf(c.Str("%s Case %d:\n%s\n\n"), c.AllocaCStr(testName), c.Int(i+1), json.Print()) + result := converter.MarshalASTFiles() + str := result.Print() + c.Printf(c.Str("%s Case %d:\n%s\n\n"), c.AllocaCStr(testName), c.Int(i+1), str) + cjson.FreeCStr(str) + result.Delete() converter.Dispose() } }