diff --git a/host.go b/host.go index b0d1381..a31bc32 100644 --- a/host.go +++ b/host.go @@ -309,6 +309,7 @@ func buildEnvModule(ctx context.Context, rt wazero.Runtime, extism api.Module) ( hostFunc(name, func(ctx context.Context, m api.Module, offset uint64) { if plugin, ok := ctx.Value(PluginCtxKey("plugin")).(*Plugin); ok { if LogLevel(pluginLogLevel.Load()) > level { + plugin.currentPlugin().Free(offset) return } @@ -319,6 +320,8 @@ func buildEnvModule(ctx context.Context, rt wazero.Runtime, extism api.Module) ( plugin.Log(level, message) + plugin.currentPlugin().Free(offset) + return } @@ -414,6 +417,8 @@ func varGet(ctx context.Context, m api.Module, offset uint64) uint64 { panic(fmt.Errorf("failed to read var name from memory: %v", err)) } + cp.Free(offset) + value, ok := plugin.Var[name] if !ok { // Return 0 without an error if key is not found @@ -448,6 +453,8 @@ func varSet(ctx context.Context, m api.Module, nameOffset uint64, valueOffset ui panic(fmt.Errorf("failed to read var name from memory: %v", err)) } + cp.Free(nameOffset) + // Remove if the value offset is 0 if valueOffset == 0 { delete(plugin.Var, name) @@ -459,6 +466,8 @@ func varSet(ctx context.Context, m api.Module, nameOffset uint64, valueOffset ui panic(fmt.Errorf("failed to read var value from memory: %v", err)) } + cp.Free(valueOffset) + // Calculate size including current key/value size := int(unsafe.Sizeof([]byte{})+unsafe.Sizeof("")) + len(name) + len(value) for k, v := range plugin.Var { @@ -485,6 +494,7 @@ func httpRequest(ctx context.Context, m api.Module, requestOffset uint64, bodyOf var request HttpRequest err = json.Unmarshal(requestJson, &request) + cp.Free(requestOffset) if err != nil { panic(fmt.Errorf("invalid http request: %v", err)) }