Skip to content

Commit

Permalink
Tweak free calls
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com>
  • Loading branch information
gmlewis committed Jun 15, 2024
1 parent 25146cc commit 0246b31
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion extism_pdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ func OutputJSON(v any) error {
return err
}

OutputMemory(AllocateBytes(b))
mem := AllocateBytes(b)
defer mem.Free()
OutputMemory(mem)
return nil
}

Expand Down Expand Up @@ -149,11 +151,13 @@ func SetError(err error) {

func SetErrorString(err string) {
mem := AllocateString(err)
defer mem.Free()
extism_error_set(mem.offset)
}

func GetConfig(key string) (string, bool) {
mem := AllocateBytes([]byte(key))
defer mem.Free()

offset := extism_config_get(mem.offset)
clength := extism_length(offset)
Expand Down Expand Up @@ -189,6 +193,7 @@ func Log(level LogLevel, s string) {

func GetVar(key string) []byte {
mem := AllocateBytes([]byte(key))
defer mem.Free()

offset := extism_var_get(mem.offset)
clength := extism_length(offset)
Expand All @@ -204,6 +209,7 @@ func GetVar(key string) []byte {

func SetVar(key string, value []byte) {
keyMem := AllocateBytes([]byte(key))
defer keyMem.Free()

valMem := AllocateBytes(value)

Expand All @@ -212,6 +218,7 @@ func SetVar(key string, value []byte) {

func GetVarInt(key string) int {
mem := AllocateBytes([]byte(key))
defer mem.Free()

offset := extism_var_get(mem.offset)
clength := extism_length(offset)
Expand All @@ -227,6 +234,7 @@ func GetVarInt(key string) int {

func SetVarInt(key string, value int) {
keyMem := AllocateBytes([]byte(key))
defer mem.Free()

bytes := make([]byte, 8)
binary.LittleEndian.PutUint64(bytes, uint64(value))
Expand All @@ -238,6 +246,7 @@ func SetVarInt(key string, value int) {

func RemoveVar(key string) {
mem := AllocateBytes([]byte(key))
defer mem.Free()
extism_var_set(mem.offset, 0)
}

Expand Down

0 comments on commit 0246b31

Please sign in to comment.