@@ -309,6 +309,7 @@ func buildEnvModule(ctx context.Context, rt wazero.Runtime, extism api.Module) (
309309 hostFunc (name , func (ctx context.Context , m api.Module , offset uint64 ) {
310310 if plugin , ok := ctx .Value (PluginCtxKey ("plugin" )).(* Plugin ); ok {
311311 if LogLevel (pluginLogLevel .Load ()) > level {
312+ plugin .currentPlugin ().Free (offset )
312313 return
313314 }
314315
@@ -319,6 +320,8 @@ func buildEnvModule(ctx context.Context, rt wazero.Runtime, extism api.Module) (
319320
320321 plugin .Log (level , message )
321322
323+ plugin .currentPlugin ().Free (offset )
324+
322325 return
323326 }
324327
@@ -414,6 +417,8 @@ func varGet(ctx context.Context, m api.Module, offset uint64) uint64 {
414417 panic (fmt .Errorf ("failed to read var name from memory: %v" , err ))
415418 }
416419
420+ cp .Free (offset )
421+
417422 value , ok := plugin .Var [name ]
418423 if ! ok {
419424 // 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
448453 panic (fmt .Errorf ("failed to read var name from memory: %v" , err ))
449454 }
450455
456+ cp .Free (nameOffset )
457+
451458 // Remove if the value offset is 0
452459 if valueOffset == 0 {
453460 delete (plugin .Var , name )
@@ -459,6 +466,8 @@ func varSet(ctx context.Context, m api.Module, nameOffset uint64, valueOffset ui
459466 panic (fmt .Errorf ("failed to read var value from memory: %v" , err ))
460467 }
461468
469+ cp .Free (valueOffset )
470+
462471 // Calculate size including current key/value
463472 size := int (unsafe .Sizeof ([]byte {})+ unsafe .Sizeof ("" )) + len (name ) + len (value )
464473 for k , v := range plugin .Var {
@@ -485,6 +494,7 @@ func httpRequest(ctx context.Context, m api.Module, requestOffset uint64, bodyOf
485494
486495 var request HttpRequest
487496 err = json .Unmarshal (requestJson , & request )
497+ cp .Free (requestOffset )
488498 if err != nil {
489499 panic (fmt .Errorf ("invalid http request: %v" , err ))
490500 }
0 commit comments