diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 5d5a07b..b31ab91 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1739,9 +1739,13 @@ impl Call for MyCall<'_> { let src = self.stack.pop().unwrap(); let src = src.cast_bound::(py).unwrap(); let len = src.len().unwrap(); + let layout = Layout::from_size_align(len, 1).unwrap(); let dst = unsafe { - let dst = alloc::alloc(Layout::from_size_align(len, 1).unwrap()); + let dst = alloc::alloc(layout); slice::from_raw_parts_mut(dst, len).copy_from_slice(src.as_bytes()); + // The lowered list is only read during the call, so free + // it when the call ends. + self.defer_deallocate(dst, layout); dst }; Some((dst as _, len))