From c03acd720906d9c9bba9aad05b3b8e90e57d7c46 Mon Sep 17 00:00:00 2001 From: Flier Lu Date: Wed, 23 Oct 2024 09:29:41 +0800 Subject: [PATCH] remove go pointer in array --- internal/hs/compile.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/hs/compile.go b/internal/hs/compile.go index ce6b85d..c34382e 100644 --- a/internal/hs/compile.go +++ b/internal/hs/compile.go @@ -161,12 +161,12 @@ type ExprExt struct { HammingDistance uint32 } -func (e *ExprExt) c() *C.hs_expr_ext_t { +func (e *ExprExt) c() (ext *C.hs_expr_ext_t) { if e == nil { return nil } - var ext C.hs_expr_ext_t + ext = (*C.hs_expr_ext_t)(C.malloc(C.sizeof_hs_expr_ext_t)) if e.Flags&ExtMinOffset != 0 { ext.flags |= C.HS_EXT_FLAG_MIN_OFFSET @@ -189,7 +189,7 @@ func (e *ExprExt) c() *C.hs_expr_ext_t { ext.hamming_distance = C.uint(e.HammingDistance) } - return &ext + return } func ExpressionInfo(expression string, flags CompileFlag) (*ExprInfo, error) { @@ -443,6 +443,8 @@ func CompileMulti(input Patterns, mode ModeFlag, info *PlatformInfo) (Database, flags[i] = C.uint(pattern.Flags) ids[i] = C.uint(pattern.ID) exts[i] = pattern.Ext.c() + + p.Pin(exts[i]) } ret := C.hs_compile_ext_multi(cexprs, cflags, cids, cexts, C.uint(n), C.uint(mode), platform, &db, &err) @@ -451,6 +453,10 @@ func CompileMulti(input Patterns, mode ModeFlag, info *PlatformInfo) (Database, C.free(unsafe.Pointer(expr)) } + for _, ext := range exts { + C.free(unsafe.Pointer(ext)) + } + if err != nil { defer C.hs_free_compile_error(err) }