diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 287fe90..d9de25f 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -310,6 +310,9 @@ impl MemoryBlock { /// Allocate a block of memory and return the offset #[no_mangle] pub unsafe fn extism_alloc(n: Length) -> Pointer { + if n == 0 { + return 0; + } let region = MemoryRoot::new(); let block = region.alloc(n); match block { @@ -321,6 +324,9 @@ pub unsafe fn extism_alloc(n: Length) -> Pointer { /// Free allocated memory #[no_mangle] pub unsafe fn extism_free(p: Pointer) { + if p == 0 { + return; + } let block = MemoryRoot::new().find_block(p); if let Some(block) = block { block.free(); diff --git a/runtime/src/current_plugin.rs b/runtime/src/current_plugin.rs index 9375d56..bf3dc31 100644 --- a/runtime/src/current_plugin.rs +++ b/runtime/src/current_plugin.rs @@ -125,6 +125,12 @@ impl CurrentPlugin { } pub fn memory_alloc(&mut self, n: u64) -> Result { + if n == 0 { + return Ok(MemoryHandle { + offset: 0, + length: 0, + }); + } let (linker, mut store) = self.linker_and_store(); let output = &mut [Val::I64(0)]; if let Some(f) = linker.get(&mut store, "env", "extism_alloc") { diff --git a/runtime/src/extism-runtime.wasm b/runtime/src/extism-runtime.wasm index b252b6f..67db362 100755 Binary files a/runtime/src/extism-runtime.wasm and b/runtime/src/extism-runtime.wasm differ