Skip to content

Commit

Permalink
cleanup: host takes ownership of memory handles passed to config/var/…
Browse files Browse the repository at this point in the history
…error/http functions
  • Loading branch information
zshipko committed Sep 19, 2024
1 parent 9e1a43e commit 56cdb73
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/call-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ export class CallContext {

const key = item.string();

this.free(addr);

Check failure on line 299 in src/call-context.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Property 'free' does not exist on type 'CallContext'.

Check failure on line 299 in src/call-context.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Property 'free' does not exist on type 'CallContext'.

if (key in this.#config) {
return this.store(this.#config[key]);
}
Expand All @@ -309,9 +311,10 @@ export class CallContext {
if (item === null) {
return 0n;
}
this.free(addr);

const key = item.string();
this.free(addr);

Check failure on line 316 in src/call-context.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Property 'free' does not exist on type 'CallContext'.

Check failure on line 316 in src/call-context.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Property 'free' does not exist on type 'CallContext'.

const result = this.getVariable(key);
const stored = result ? this[STORE](result.bytes()) || 0 : 0;
return Block.indexToAddress(stored)
Expand All @@ -324,9 +327,9 @@ export class CallContext {
this.#logger.error(`attempted to set variable using invalid key address (addr="${addr.toString(16)}H")`);
return;
}
this.free(addr);

const key = item.string();
this.free(addr);

Check failure on line 332 in src/call-context.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Property 'free' does not exist on type 'CallContext'.

if (valueaddr === 0n) {
this.deleteVariable(key)
Expand All @@ -346,13 +349,12 @@ export class CallContext {
const copied = new Uint8Array(valueBlock.buffer.byteLength)
copied.set(new Uint8Array(valueBlock.buffer), 0)
this.setVariable(key, copied);
this.free(valueaddr);

Check failure on line 352 in src/call-context.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Property 'free' does not exist on type 'CallContext'.
} catch (err: any) {
this.#logger.error(err.message)
this.setError(err)
return;
}

this.free(valueaddr);
},

http_request: (_requestOffset: bigint, _bodyOffset: bigint): bigint => {
Expand Down

0 comments on commit 56cdb73

Please sign in to comment.